【发布时间】:2012-09-23 09:12:56
【问题描述】:
我有这个字符串
$s = 'Yo be [diggin = array("fruit"=> "apple")] scriptzors!';
然后被检查
$matches = null;
preg_match_all('/\[(.*?)\]/', $s, $matches);
var_dump($matches[1]);
但我想要它做的是以下内容,它应该返回以下内容
print "yo be";
$this->diggin(SEND ARRAY HERE);
print "scriptzors!";
编辑以显示以下答案的问题
$s = 'Yo be [diggin = array("fruit"=>"apple")] scriptzors!';
$matches = null;
preg_match_all('/\[(.*?)\]/', $s, $matches);
$var = explode(' = ', $matches[1]);
print $var[0]; //THIS DOES NOT PRINT
【问题讨论】:
-
返回部分对我来说很奇怪。你的 $s 字符串应该转换成什么?
-
它只是来自我们数据库的文本,我希望我们的员工能够在网站内容中购买插件或运行功能。像 wordpress 一样思考
-
这是什么 "$this->diggin(SEND ARRAY HERE);"做?转换后的输出是什么样的?
标签: php preg-replace preg-match preg-match-all