Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP-从括号内获取参数_Php_Arguments_Brackets - Fatal编程技术网

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”时,我将其保存到变量中,然后替换所有[]函数。