php正则去掉空格的方法:首先创建一个PHP示例文件;然后定义一个有空格的字符串;最后通过“preg_replace("/(\s|\ \;| |\xc2\xa0)/","",$str);”方式去掉字符串中的空格即可。
本文操作环境:Windows7系统、PHP7.1版、Dell G3电脑。
php 正则去掉
立即学习“PHP免费学习笔记(深入)”;
空格$str=' <p> </p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</p> <p> </p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</p> <p> </p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</p> <p> </p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</p> <p><strong><span style="font-size: 18px;">Factory Supply High Quality Maitake Mushroom Extract Powder Bulk</span></strong></p> <p> </p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</p> <p> </p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</p>Product Name <p> </p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</p>'; $uuu=preg_replace("/(\s|\ \;| |\xc2\xa0)/","",$str); echo str_replace('<p></p>', '', $uuu);
很完美。
php的str_replace函数怎么把
立即学习“PHP免费学习笔记(深入)”;
立即学习“PHP免费学习笔记(深入)”;
php的str_replace函数怎么把
$html="<p>fdasf</p>"; echo $string = str_replace(array("<p>","","</p>"),"",$html); br<http://bbs.houdunwang.com/> 若是<p> 内容</p>替换成<p>内容</p><p> content</p>替换成<p>contend</p>(空格是tab键和空格键 混合的 都有可能)方法如下 $html=preg_replace('/[\n\r\t]/','',$html);//去空格 若是<p>后面跟了若干个,再是内容 <p> 内容</p> 替换成<p>内容</p> <p> content</p> 替换成<p>contend</p> <?php $html="<p> 内容</p>替换成<p>内容</p> <p>content</p>替换成<p>contend</p>";方法如下 $html=trim($html); $html=str_replace(PHP_EOL,"",$html); $html=str_replace(" ","",$html); $html=preg_replace('/\s+/','',$html); $html=preg_replace('/[\n\r\t]/','',$html); echo "{$html}"; ?> str_replace("<p><br\/><\/p>","",$htmlstr);
【推荐学习:《PHP视频教程》】
以上就是php怎么实现正则去掉空格的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号