PHP-从括号内获取参数
我想把信息放在括号里 例如:PHP-从括号内获取参数,php,arguments,brackets,Php,Arguments,Brackets,我想把信息放在括号里 例如: [Article title="Article 1" show="Article Name Goes Here"] <p>Some other simple text here...</p> [Article title="Article 2" show="Article Name Goes Here"] [Article title=“Article 1”show=“文章名称在此显示”] 这里还有一些简单的文字 [Article titl
[Article title="Article 1" show="Article Name Goes Here"]
<p>Some other simple text here...</p>
[Article title="Article 2" show="Article Name Goes Here"]
[Article title=“Article 1”show=“文章名称在此显示”]
这里还有一些简单的文字
[Article title=“Article 2”show=“文章名称在此显示”]
我试图将“参数”设置为变量,这样我就可以从数据库中获取文章1的信息,并将其替换为完整内容。使用explode或substring。substr可能更快,更不容易出错
$string = '[Article title="Article 1" show="Article Name Goes Here"]';
$arg1 = substr($string, strrpos($string, "title=")+len("title="), strrpos($string, "show="));
$arg2 = substr($string, strrpos($string, "show=")+len("title="), strrpos($string, -1));
您可能需要处理一些strrpos值,因为我没有考虑qoutemarks。您需要查看preg_match和正则表达式来执行类似操作,或者您可以使用explode。“将其替换为完整内容。”完整内容在哪里。。。?你说的争论是什么意思?$FullContent数据库中保存的所有文本。。。当我从数据库中获取“FullContent”时,我将其保存到变量中,然后替换所有[]函数。