Page 1 of 1

preg_replace: how do I strip off all white space and  ?

Posted: Fri Sep 24, 2010 11:46 am
by lauthiamkok
Hi,

how do I strip off all white space and  ?

I have this as a input in a wrapper I create,

      bold      

so before turning the text to bold, i want to strip off all white spaces and &nbsp, and turn it into bold,

Code: Select all

$this->content = preg_replace("/\[(.*?)\]\s\s+(.*?)\s\s+\[\/(.*?)\]/", 
				"[$1]$2[/$3]", 
				$this->content);
but it does not work! can you help please?

Many thanks,
Lau

Re: preg_replace: how do I strip off all white space and &nb

Posted: Fri Sep 24, 2010 11:51 am
by John Cartwright
If you are working with html entities, you either need to convert them to their respective characters or adjust your pattern to match the entities.

Try

Code: Select all

$this->content = preg_replace("/\[(.*?)\]\s*(.*?)\s*\[\/(.*?)\]/", "[$1]$2[/$3]", html_entity_decode($this->content));

Re: preg_replace: how do I strip off all white space and &nb

Posted: Fri Sep 24, 2010 12:03 pm
by lauthiamkok
John Cartwright wrote:If you are working with html entities, you either need to convert them to their respective characters or adjust your pattern to match the entities.
[/syntax]
yes it is a form input pass from tiny MCE and it generates   when u put spaces in the form input.
John Cartwright wrote:
Try

Code: Select all

$this->content = preg_replace("/\[(.*?)\]\s*(.*?)\s*\[\/(.*?)\]/", "[$1]$2[/$3]", html_entity_decode($this->content));
it works perfectly with this! thanks so much! :D