1

我有如下所示的字符串,并想使用 PHP 从中检索“示例文本”。有人可以帮忙吗?可以使用 preg_match 完成吗?** [[示例文本]]

4

2 回答 2

2

试试这个:

$text = '[This] is a [[test]] string.';
preg_match("/\[\[.*?\]\]/",$text,$matches);
var_dump($matches);

如果有多个模式:

$text = '[This] is a [[test]] [[string]].';
preg_match_all("/\[\[.*?\]\]/",$text,$matches);
var_dump($matches);

实时执行:eval.in

可能,您也需要它以供将来参考此类问题:http ://webcheatsheet.com/php/regular_expressions.php

于 2013-05-30T19:33:58.953 回答
0

如果它始终是您要删除的第一个和最后两个字符,只需使用 substring 即可。或进行替换...检查一下: http: //php.net/manual/de/function.substr-replace.php

于 2013-05-30T19:33:55.217 回答