一个php变量封装进数组的问题
遇到一个关于json的问题。有一组正则规则,由于有很多行(以后可能还需要增删)
所以在主页页面里用一个固定的foreach代码,然后将正则规则封装一个json数组,保存到外部文件(以后修改规则时只需修改这个外部文件)。
json.txt代码
$json=<<<EOT<br />[{"a":"!preg_match([email protected]\\\.aaa\\\.com@',$url,$match)||!preg_match([email protected]\\\.bbb\\\.com@',$url,$match)||!preg_match([email protected]\\\.ccc\\\.com@',$url,$match)","b":"1"},{"a":"!preg_match([email protected]\\\.ddd\\\.com@',$url,$match)||!preg_match([email protected]\\\.eee\\\.com@',$url,$match)","b":"2"},{"a":"!preg_match([email protected]\\\.fff\\\.com@',$url,$match)||!preg_match([email protected]\\\.ggg\\\.com@',$url,$match)","b":"3"}]<br />EOT;<br />
php页面代码
<br />include("json.txt");<br />$date = json_decode($json);<br />foreach($date as $row){<br /> if($row->a){<br /> //做一些$row->b的事物<br /> }<br />}
但是现在$url,$match2个php变量在json_decode后消失了,试加花括号{$url},{$match2}也没用。
现在如何解决这个问题?不行的话不用json也可以。最终目前是封装成一个数值,可以用foreach循环读出。谢谢。
json php
——解决方案——————–
$json=<<<'EOT'
….
EOT;
就不会使变量“消失
本文来源gao!%daima.com搞$代*!码$网3
搞代gaodaima码”
但我不是道你对 ‘$var’ 如何还原成变量