djtozz Posted November 13, 2009 Share Posted November 13, 2009 Hi, I'm using a little scirpt that creates rss feeds for my mysql table. works fine, except for the records that have a "&" in my table. I've tried to following: $caption = str_replace("&","and",$caption); but this doesn't seems to work, can somebody help me with this please ? Are there maybe other functions out there that can do the same? (converting the 'illegal' characters from a variable to the right format for xml) Thanks, Link to comment https://forums.phpfreaks.com/topic/181362-solved-prepairing-string-for-xml/ Share on other sites More sharing options...
Schlo_50 Posted November 13, 2009 Share Posted November 13, 2009 Try this. <?php $caption = "I ate fish & chips for dinner"; $replaceCharacter = str_replace("&","and",$caption); echo $replaceCharacter; ?> Link to comment https://forums.phpfreaks.com/topic/181362-solved-prepairing-string-for-xml/#findComment-956717 Share on other sites More sharing options...
thebadbad Posted November 13, 2009 Share Posted November 13, 2009 I think htmlspecialchars() would do the job (converting & to &). Link to comment https://forums.phpfreaks.com/topic/181362-solved-prepairing-string-for-xml/#findComment-956719 Share on other sites More sharing options...
Schlo_50 Posted November 13, 2009 Share Posted November 13, 2009 If it's another function you're after, you could even try preg_replace(). Link to comment https://forums.phpfreaks.com/topic/181362-solved-prepairing-string-for-xml/#findComment-956721 Share on other sites More sharing options...
djtozz Posted November 13, 2009 Author Share Posted November 13, 2009 Thanks guys, Schlo_50 : your solution worked for me, thank you Thebadbad: htmlspecialchars was exactly what I was looking for! Thanks a lot! Link to comment https://forums.phpfreaks.com/topic/181362-solved-prepairing-string-for-xml/#findComment-956732 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.