Posted By

macodev on 11/16/11


Tagged

trim br


Versions (?)

Trim BR tags from string


 / Published in: PHP
 

Deletes empty spaces and br tags on start and end of a string

  1. function trim_br($string){
  2. $string = preg_replace('/^\s*(?:<br\s*\/?>\s*)*/i', '', $string);
  3. $string = preg_replace('/\s*(?:<br\s*\/?>\s*)*$/i', '', $string);
  4. return $string;
  5. }
  6. echo "**".trim_br('<br /> <br/>example text <br/> newline <br />')."**";

Report this snippet  

You need to login to post a comment.