0

我正在尝试从字符串中删除一些块,这基本上是 html 代码;块由# I'm a zero with regexp 分隔,但在另一个 SO 主题上找到了此方法(在 php 中使用 regex 替换所有字符之间和包括两个字符)但它不起作用,我无法得到原因。我的块是 html 代码中的占位符,如下所示:

#TEXT_2#

我尝试了这些功能(没有一个成功):

$text = preg_replace('/\[[#]]*]/', '', $text);
$text = preg_replace("/\\#\\\(\d).*?\\#/", "", $text);
$text = preg_replace( '~\#(\d+)\#~' , "", $text);

有人可以建议我一种方法吗?任何帮助将不胜感激。谢谢

4

2 回答 2

1
echo preg_replace('/#\w+#/', '', $text);
于 2013-07-26T14:15:23.967 回答
1
$text = "#in1#out1#in2#out2#in3###out3";
$text = preg_replace('/#[^#]*#/', '', $text);
echo $text, PHP_EOL;

它应该只回显输出部分,即:out1out2out3

于 2013-07-26T14:16:38.813 回答