Home > Backend Development > PHP Tutorial > 如何去掉字符串首尾部一个或多个换行符<br />

如何去掉字符串首尾部一个或多个换行符<br />

WBOY
Release: 2016-06-13 13:34:10
Original
1077 people have browsed it

怎么去掉字符串首尾部一个或多个换行符

怎么去掉字符串尾部一个或多个换行符


$str=“


文字

 

 



";



$str=preg_replace("/^[
]+|[
]+$/","",$str);
怎么写才正确?

------解决方案--------------------
$str = str_replace('
','',$str);
------解决方案--------------------

PHP code
<?php $str=<<<HTML
<br /> <br> <br>文<br>字<br><br>   
<br>   
<br><br><br>
HTML;
echo preg_replace('/(^(<br>\s*)+)|((<br>\s*)+$)/is','',$str); <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template