Return to Snippet

Revision: 53225
at December 31, 2011 01:33 by macodev


Updated Code
function trim_br($string){
 $string = preg_replace('/^\s*(?:<br\s*\/?>\s*)*/i', '', $string);
 $string = preg_replace('/\s*(?:<br\s*\/?>\s*)*$/i', '', $string);
 return	$string;
}
echo "**".trim_br('<br /> <br/>example text <br/> newline <br />')."**";

Revision: 53224
at November 16, 2011 22:52 by macodev


Initial Code
function trim_br($string){
 //elimina spazi vuoti e tag br a inizio e fine stringa
 $string = preg_replace('/^\s*(?:<br\s*\/?>\s*)*/i', '', $string);
 $string = preg_replace('/\s*(?:<br\s*\/?>\s*)*$/i', '', $string);
 return	$string;
}
echo "**".trim_br('<br /> <br/>esempio testo <br/> a capo <br />')."**";

Initial URL

                                

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

Initial Title
Trim BR tags from string

Initial Tags

                                

Initial Language
PHP