Moron Posted March 4, 2011 Share Posted March 4, 2011 What I want to do should be very simple, but I've stared at code all day and can't grasp it. I want to replace the "&" character, if it exists, with the "&" string. What I have is: $name = $RESULT['ACCOUNT_NAME']; $cleaned = str_replace('&','& ', $name); echo $cleaned; It doesn't crash or anything, but it doesn't work. I have several ampersand (&) characters in my output that aren't getting replaced. Any help is appreciated. Link to comment https://forums.phpfreaks.com/topic/229613-frustrated-str_replace-help-please/ Share on other sites More sharing options...
kenrbnsn Posted March 4, 2011 Share Posted March 4, 2011 You need to do a show source in your web browser to see that the str_replace worked. When you echo "&", your browser will display "&". Ken Link to comment https://forums.phpfreaks.com/topic/229613-frustrated-str_replace-help-please/#findComment-1182980 Share on other sites More sharing options...
Moron Posted March 4, 2011 Author Share Posted March 4, 2011 You need to do a show source in your web browser to see that the str_replace worked. When you echo "&", your browser will display "&". Ken Great point and I hadn't caught that. So since this will be copied and pasted as an XML document, I guess I need to make it actually display "$amp;." Thanks. That helps. Link to comment https://forums.phpfreaks.com/topic/229613-frustrated-str_replace-help-please/#findComment-1183008 Share on other sites More sharing options...
gizmola Posted March 4, 2011 Share Posted March 4, 2011 HTML does have a special tag for this type of situaion: --- . Link to comment https://forums.phpfreaks.com/topic/229613-frustrated-str_replace-help-please/#findComment-1183010 Share on other sites More sharing options...
Moron Posted March 4, 2011 Author Share Posted March 4, 2011 HTML does have a special tag for this type of situaion: --- <pre>. I tried the <pre></pre> tags but they also cause a carriage break and that won't work. Maybe I can find a way to have "&" and "amp" and ";" all line up together but not be read as a tag. Link to comment https://forums.phpfreaks.com/topic/229613-frustrated-str_replace-help-please/#findComment-1183017 Share on other sites More sharing options...
Pikachu2000 Posted March 4, 2011 Share Posted March 4, 2011 If you want to literally echo '&' use this, or use it in conjunction with str_replace(). echo '&'; Link to comment https://forums.phpfreaks.com/topic/229613-frustrated-str_replace-help-please/#findComment-1183020 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.