Preg/str replace

Hi,

I’m having trouble replacing some text. So far I have:


$new = str_replace('style="font-family: Interstate-Regular; font-size: xx-small;"', '', '<p><strong><span style="font-family: Interstate-Bold; font-size: xx-small;"></span>');
echo $new;

It won’t work and I can’t see why? Its just testing at this stage, I have a loop through the DB to remove all the rubbish formatting thanks to “data inputters”.

Cheers,
Rhys

Could you give an example of input and desired output?

Hi,
Input is anything really. I have all rows in the table returned if the description contains xx-small.
Input is usually lots of text with:
TEXT…<span style=“font-family: Interstate-Bold; font-size: xx-small;”>…TEXT…</span>…TEXT…

And I want to return:
TEXT…<span>…TEXT…</span>…TEXT…

Basically remove the styling added by tinymce and the data inputters.

In this case you’d better use preg_replace, because the “rubbish formatting” can have many forms, right?
For example:

preg_replace('/<span[^>]*>/', '<span>', '<p><strong><span style="font-family: Interstate-Bold; font-size: xx-small;"></span>');

gets rid of all that is written inside the span tag and returns:

<p><strong><span></span>

Thanks,

If I wanted to keep everything but the xx-small, would something like this work:


preg_replace('/<span[^style=\\"font-family: (.+?)\\">]*>/', '<span style="font-family: \\\\1;">', '<p><strong><span style="font-family: Interstate-Bold; font-size: xx-small;"></span>');

You can try it out here (for example, googling will give you other regex test sites as well): http://www.spaweditor.com/scripts/regex/

That’s a great tool. Thanks. I went with your code in the end as no styling is needed.

Cheers,
Rhys.