Forum Moderators: coopster

Message Too Old, No Replies

replacing an & when not an entity

I so suck at regex

         

ianevans

12:52 am on Nov 23, 2004 (gmt 0)

10+ Year Member



I've noticed that the amazonlib functions are changing the ampersands in the XML in an Amazon XML request.

The author says he'll be looking at a fix eventually, but as I'm using the info to drum up some Xmas sales, I thought I'd whip up a script to go through my database and fix it up.

I've mentioned before that I suck at regex's so if anyone can suggest the appropriate way to do this I'd appreciate it.

Here's the problem:

The amazonlib functions are turning the something like:
Thelma & Louise into Thelma&Louise

I need to search and replace an ampersand with a space, an &, and a space (" & ") when the next word is not part of an entity.

So, it'll turn:

Thelma&Louise say "Webmasterworld is the best"

into

Thelma & Louise say "Webmasterworld is the best"

Any regex suggestions are greatly, greatly appreciated.

saoi_jp

2:52 am on Nov 23, 2004 (gmt 0)

10+ Year Member



It'd be tough to not miss something like Thelma&Louise;

How about
$title = html_entity_decode($title);
to change " into ", etc
Then
$title = str_replace("&", " & ", $title);
to get the spaces, and finally
$title = htmlentities($title);
to put it all back?