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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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: --- . Quote Link to comment 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. Quote Link to comment 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 '&'; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.