Preg_match从Html中提取Json

时间:2013-12-04 04:46:50

标签: php

$ data(HTML Response):

...
<script type="text/javascript">
//<![CDATA[
WebForm_AutoFocus('drpDwnLstLinhas');Sys.Application.add_init(function() {
$create(Artem.Google.MarkersBehavior, {"markerOptions":..EXTENSIVE JSON..,"name":"map_GoogleMarkers"}, null, null, $get("map"));
});
//]]>
</script>
...

我想提取:{"markerOptions":..EXTENSIVE JSON..,"name":"map_GoogleMarkers"}

代码:

preg_match('~$create(Artem.Google.MarkersBehavior, (.*?), null, null, $get("map"));~', $data, $json);
var_dump($json); //empty

1 个答案:

答案 0 :(得分:1)

你只需要逃避“$”和“(”和“)”

preg_match('~\$create\(Artem.Google.MarkersBehavior, (.*), null, null, \$get\("map"\)\);~', $data, $json);

测试。