2

I have some html code, which also includes a javascript tag and some json inside.

The json object looks like this:

var data =  {"service_notice":"111111-aa-bb-222222"}

I would like to extract the value for service_notice. How can this be done with regex?

I am also concerned that it could be formatted slightly differently:

var data =  {"service_notice" : "111111-aa-bb-222222"}

or

var data = {
    "service_notice" : 
        "111111-aa-bb-222222" }
4

1 回答 1

2

您可以使用json_decode

 json_decode(substr($code, strpos($code, "{")-1, strpos($code, "}") - strpos($code, "{") + 2), true)

将产生一个看起来像的数组

 array("service_notice"=>"111111-aa-bb-222222");

谢谢@HamZaDzCyber​​DeV

于 2013-05-24T18:46:16.607 回答