tags:

views:

142

answers:

5

I need to strip all <br /> and all 'quotes' (") and all 'ands' (&) and replace them with a space only ...

How can I do this? (in PHP)

I have tried this for the <br />:

   $description = preg_replace('<br />', '', $description);

But it returned <> in place of every <br />...

Thanks

+1  A: 

str_replace is your friend.

TheGrandWazoo
look at my update... I have ALSO tried this with str_replace
Camran
preg_replace matches on a regular expression and then replaces it's match. Another solution is a combination of str_replace and striptags.
TheGrandWazoo
examples would be very much appreciated :)
Camran
$description = strip_tags($description); $description = str_replace('"', ' ', $description); $description = str_replace('
TheGrandWazoo
A: 

You can use str_replace like this:

  str_replace("<br/>", " ", $orig );

preg_replace etc uses regular expressions and that may not be what you want.

Vincent Ramdhanie
wont work, look at my update, same results!
Camran
Show us an example. This is a pretty straight forward function and it works fine for me. Maybe something else is wrong.
Vincent Ramdhanie
+2  A: 

To manipulate HTML it is generally a good idea to use a DOM aware tool instead of plain text manipulation tools (think for example what will happen if you enounter variants like <br/>, <br /> with more than one space, or even <br> or <BR/>, which altough illegal are sometimes used). See for example here: http://sourceforge.net/projects/simplehtmldom/

Konamiman
Hmmm, seems to me that stripping might at least be a different case than other manipulations. 's what we have strip_tags() for.
Tchalvak
+1  A: 

To remove all permutations of br:

<br> <br /> <br/> <br   >

check out the user contributed strip_only() function in

http://www.php.net/strip%5Ftags

The "Use the DOM instead of replacing" caveat is always correct, but if the task is really limited to these three characters, this should be o.k.

Pekka
+2  A: 

If str_replace() isnt working for you, then something else must be wrong, because

$string = 'A string with <br/> & "double quotes".';
$string = str_replace(array('<br/>', '&', '"'), ' ', $string);
echo $string;

outputs

A string with      double quotes .

Please provide an example of your input string and what you expect it to look like after filtering.

Gordon
Heh, perhaps he double quoted the original string.
Tchalvak