Trim BR tags from string


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.