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
Php 试图从\u内容中删除三个或更多_Php_Regex - Fatal编程技术网

Php 试图从\u内容中删除三个或更多

Php 试图从\u内容中删除三个或更多,php,regex,Php,Regex,正如标题所说,我正试图从get_内容中删除并替换三个或更多;在我的single.php中 我目前正在使用它,但它似乎对文档中的数据量没有任何影响 $content = get_the_content(); $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]&gt;', $content); $content = preg_replace('/(<br[\s]?

正如标题所说,我正试图从get_内容中删除并替换三个或更多;在我的single.php中

我目前正在使用它,但它似乎对文档中的数据量没有任何影响

$content = get_the_content();
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]&gt;', $content);
$content = preg_replace('/(<br[\s]?[\/]?>[\s]*){3,}/', '<br /><br />', $content);
$content = strip_tags($content, '<br> <p> <a>');
echo $content; 
这给了我输出:

<br />
<br />
<br />
<a href="http://1.bp.blogspot.com/-rYRPguEjEl8/UrSWUC_jEOI/AAAAAAAANm4/qVle4zdVfsQ/s1600/Alexa+NYC.jpg" imageanchor="1"></a>

<p>
<br />
<br />You don&#8217;t always have to stick to the same colour scheme 
<br />
<br />
<br />
<br />
我似乎无法使正则表达式正常工作。

请尝试以下代码:

<?PHP
$input ="<br/><br/><br/><br/>Hello";
highlight_string($input);
$output = preg_replace('/(<br\s*\/?>\s*){3,}/', '<br/><br/>', $input);
highlight_string($output);
?>

不要将正则表达式用于HTML@ConnorPeet上的人们非常喜欢说不要将正则表达式用于HTML!。。。但是他们没有给出解决方案,因为使用DOM或simpleXML来解决上述问题是一个集群,他们最终使用正则表达式来解决它。就像这个问题的公认答案一样:@DigitalChris我在其他东西上使用DOM方法,但由于这只是重复的标记,我觉得使用regex就可以了。我已经多次看到regex的帖子:作为一个非常熟悉Js和真正的domapi的人,我喜欢DOMDocument。不过,你说得很对。突出显示字符串的作用是什么?它似乎是在输出带有html标记的文本,这不是我想要的。如果我删除highlight_字符串,效果会很好。@UzumakiDev我使用highlight_字符串显示带有html标记的输出,以显示其替换标记。