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: remove excess <br> and tags from a string - page 1
User InfoPosts
php: remove excess <br> and tags from a string#1
how can I remove excess <br> and &nbsp; tags from the start and end of a string?

Thanks :)

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


Re: php: remove excess <br> and tags from a string#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-13 18:31:01


Re: php: remove excess <br> and tags from a string#3
try this:$str = preg_replace(({^(<br(\s*/)?>|&nbsp;)+}i(, ((, $str); //from start$str = preg_replace(({(<br(\s*/)?>|&nbsp;)+$}i(, ((, $str); //from endthat also gets XHTML <br /> and <br/> forms

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


Re: php: remove excess <br> and tags from a string#4
With preg_replace:$str = "<br>some text&nbsp;"$str = preg_replace((/(^(<br>|&nbsp)*)|((<br>|&nbsp)*$)/i(, ((, $str);Didn(t test it, but something like that should work.

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


Re: php: remove excess <br> and tags from a string#5
I get unknown modifier for /g

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


Re: php: remove excess <br> and tags from a string#6
doesn't seem to pick up multiple line breaks

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


Re: php: remove excess <br> and tags from a string#7
works for me with this: $str = '<br><br>this is a test<br><br>'; Can you give me an example of a string it doesn't work with?

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


Re: php: remove excess <br> and tags from a string#8
you are right.. didn't realize my display function was performing nl2br. Thanks!

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


Re: php: remove excess <br> and tags from a string#9
You probably have to do &amp;nbsp;

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


Re: php: remove excess <br> and tags from a string#10
I don't think you need /g in PHP...?

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


Re: php: remove excess <br> and tags from a string#11
You're right, that's not a search but a replace... I'll change that now, sorry.

posted date: 2009-04-14 05:08:00


Re: php: remove excess <br> and tags from a string#12
I had the same problem. Tried &amp;nbsp; but it preserves the string exactly the same. It seems to be converting only.

posted date: 2009-04-14 05:09:00


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