Forum Moderators: coopster

Message Too Old, No Replies

preg replace help

& => &

         

AlexPoucher

12:42 am on Mar 12, 2008 (gmt 0)

10+ Year Member



I am in need of some help here, I run a script that pulls info from other sites, these sites I pull the data from don't comply well with XHTML standards and use & instead of & inside urls and titles etc.. is there something I could add to my code that would turn all instances of & to &? Thanks for your help.

WesleyC

2:40 am on Mar 12, 2008 (gmt 0)

10+ Year Member



$cleaned = preg_replace( "/&(amp;)^/", "&", $subject );

[edited by: jatar_k at 4:00 am (utc) on Mar. 12, 2008]

AlexPoucher

8:03 am on Mar 12, 2008 (gmt 0)

10+ Year Member



this is going to sound very lame, I am very new to preg_replace, would I add this code inside the <head> tags on all the pages I want this to be?

WesleyC

1:43 pm on Mar 12, 2008 (gmt 0)

10+ Year Member



This will take a string in the variable $subject and replace all instances of "&" in it with "&amp;", ignoring all already-existing instances of "&amp;". It will return the cleaned string into the variable $cleaned. :)