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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
PastorHank
Forum Contributor
Posts: 117
Joined: Sat Jun 03, 2006 7:58 am
Location: Texas Hill Country

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

Post 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
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

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

Post by s.dot »

Could you just use htmlentities for this purpose? All < > and ' " will be reverted to their html entity counterpart.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
PastorHank
Forum Contributor
Posts: 117
Joined: Sat Jun 03, 2006 7:58 am
Location: Texas Hill Country

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

Post 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....
Post Reply