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
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.

 

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.