A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearphp: trim <br> from the end of a string? - page 1
User InfoPosts
php: trim <br> from the end of a string?#1
how can I trim <br>&nbsp; from the end of a string?

posted date: 2009-04-12 23:35:00


Re: php: trim <br> from the end of a string?#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-12 23:35:01


Re: php: trim <br> from the end of a string?#3
$Output = preg_replace((/(.preg_quote((<br>&(.(nbsp;().($/i(, ((, $String);Where $String is the input and $Output is the result.

posted date: 2009-04-12 23:46:00


Re: php: trim <br> from the end of a string?#4
Why the string concatenation inside preg_quote, if I may ask?

posted date: 2009-04-13 00:00:00


Re: php: trim <br> from the end of a string?#5
SO doesn't like the entity (replaces with a real non-breaking-space ;)

posted date: 2009-04-13 07:58:00


Re: php: trim <br> from the end of a string?#6
Slightly faster, if what you are trimming is constant:$haystack = "blah blah blah <br>&"."nbsp;";$needle = "<br>&"."nbsp;";echo substr($haystack, 0, strrpos($haystack, $needle));

posted date: 2009-04-13 11:45:00


Re: php: trim <br> from the end of a string?#7
er... why not replace it with &amp;nbsp; ?

posted date: 2009-04-13 11:52:00


Re: php: trim <br> from the end of a string?#8
Because strangely, SO doesn't replace &amp; with an ampersand :-/

posted date: 2009-04-13 13:33:00


Re: php: trim <br> from the end of a string?#9
An interesting solution, but it will likely break if the needle also appears somewhere in the string, not necessarily at the end.

posted date: 2009-04-13 13:48:00


Re: php: trim <br> from the end of a string?#10
That is true. I've updated the solution to use strrpos instead of strpos, which searches from the end of the string instead.

posted date: 2009-04-14 04:32:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.