tags:

views:

331

answers:

2

I need to remove this string if found in my string:

<p><br/>   </p>

Cant replace this:

<p><br/>Test.   </p>

The whitespace expression I am using wasn't working for that, thank you for your help!

A: 

Try this:

preg_replace('%<p><br/>\s*</p>%', '', $string);

But what do you mean with Cant replace this ? Should this line also be replaced or not or how?

Update:
To clarify: Do you want to have only whitespaces removed or the whole <p><br/> </p> ?

Felix Kling
str_replace won't work with regex. replace it with `preg_replace`. Even then the tags are removed, too.
neo
@neo: Oops, thank you, I was too fast ;) I think the tags should be removed....
Felix Kling
I read the question as too remove the whitespace between the tags, but yes it can be read in both ways.
neo
thank you very much, this is working..preg_replace('!<p><br/>\s+</p>!', '', $content);Completely removes the tags.
Prime Studios
+1  A: 

Here you go:

preg_replace('!<br/>\s+</p>!', '<br/></p>', $variable_name);
Chibu
Oh: I used exclamation points so that I didn't need to escape the slashes. That will remove any whitespace and only whitespace, directly between a <br/> and a </p>.
Chibu