Page 1 of 1

Stripping out "<" and ">" while creating an xml file

Posted: Wed Dec 28, 2011 6:46 pm
by PastorHank
Couldn't think of any other way to phrase it - sorry....

Anyway, I'm extracting data from WordPress Databases and creating an xml file. I use str_replace() to strip out the embedded characters such as the '<!--> more>' or the '<strong>' etc and everything is working well.

Except when the post contains an embedded image, at that point the only common characters seem to be '<img class=> and a '/>' to mark the end, I've searched for wild card usage when replacing a string, but I can't seem to find anything out there.

If someone has any ideas or could point me in the right direction, I'd appreciate it.

Thanks

Re: Stripping out "<" and ">" while creating an xml file

Posted: Wed Dec 28, 2011 11:46 pm
by s.dot
Could you just use htmlentities for this purpose? All < > and ' " will be reverted to their html entity counterpart.

Re: Stripping out "<" and ">" while creating an xml file

Posted: Thu Dec 29, 2011 8:25 am
by PastorHank
I'll look into it, late, late, late last night I tried

Code: Select all

$s2 = preg_replace('<img .* />', '', $s1);
And it seems to work, but the file I have to check is huge, so I'm not sure it got all the little buggers....