Jump to content

Frustrated: str_replace help, please?


Moron

Recommended Posts

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

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.

 

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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.