I have a string
"PRINT CHIFFON<BR /><BR />
"
I am trying to remove any newline symbols and
tags.
$i->colour_code = str_replace('<br>', '', strip_tags($i->colour_code));
$i->colour_code = str_replace('<br \/>', '', strip_tags($i->colour_code));
$i->colour_code = preg_replace("/[
]/","",$i->colour_code);
That still does not work. Any ideas will be appreciated as this issue causes the whole system stop working
You don't need to escape the slash in the second line of replacements. In fact, since you're running it through strip_tags
, you don't even need the first two replacements. Try this:
$i->colour_code = str_replace(Array("
",""),"",strip_tags($i->colour_code));
Just make sure that $i->colour_code
is not readonly.
What do you mean it does not work? I just made a test and your code does indeed work, you have a problem with $i->colour_code.
Since you seem okay to use preg_replace, I suggest using this line of code:
$i->color_code = preg_replace('/(<br>|<br ?\/>||
)/i', '', $i->color_code);
Unlike your examples, it will be case insensitive as well, so it doesn't matter if it is br or BR.