我有一个完整的页面HTML报废,有很多标记包括HTML/CSS/JS代码。下面正则表达式从废弃的HTML提取Javascript对象
例(剥离量)
<p>blah blah blah html</p>
<script type="text/javascript">window._userData ={"country_code": "PK", "language_code": "en",user:[{"user": {"username": "johndoe", "follows":12,"biography":"blah blah blah","feedback_score":99}}],"another_var":"another value"} </script>
<script> //multiple script tags can be here... </script>
<p>blah blah blah html</p>
现在我要提取的对象中window._userData
,然后,如果可能的转换所提取的字符串到PHP对象/阵列。
我已经尝试了一些在SO上找到的正则表达式,但无法正常工作。
我也试图在这里类似的答案Regular expression extract a JavaScript variable in PHP
感谢
您想要提取的对象不正确。 – splash58
@ splash58我添加了缺少的},感谢您的评论,请解决任何问题? – Alyas
此外,它不能包含空格,并且必须包含引号中的所有键 - “{”country_code“:”PK“,”language_code“:”en“,”user“:[{”user“:{”username“:”johndoe “,”follow“:12,”biography“:”blah blah blah“,”feedback_score“:99}}],”another_var“:”另一个值“}' – splash58