Jump to content

crazy problem of "&"


diamondnular

Recommended Posts

Hi all,

 

I am trying to write a php code which will output a javascript like this:

	$text = "
<script type=\"text/javascript\">
var FO = "a&b";
        ....
</script>
";
return $text;

 

but when I check the output html code, it becomes:

 

<script type="text/javascript">
var FO = "a&b";
        ....
</script>

 

It seems that "&" has been changed to "&". How can I prevent this? How can I output just "&" in html code?

 

Thanks,

 

KC

Link to comment
Share on other sites

If you are using firefox it would be a setting particular to firefox. I would check it with IE by viewing the source.

 

I really do not like that aspect of firefox although it can be handy sometimes.

 

What browser are you using to view the source?

Link to comment
Share on other sites

Hi,

 

I just used IE to check the code, and even source code is "a&b", IE still reads the code just fine, and the code works in IE. But it seems that FF does not read the code as "a&b" then javascript does not work! It is so strange! Anybody has idea to overcome this problem?

 

Bests,

 

KC.

Link to comment
Share on other sites

You have some unescaped double quotes in your original sample. Try something like this:

Ken

 

Yes Ken, I had some typo when typing the question. But inside my real code, it was written correctlY:

 

$text = "
<script type=\"text/javascript\">
var FO = \"a&b\";
        ....
</script>
";
return $text;

Link to comment
Share on other sites

Yes Ken, I had some typo when typing the question. But inside my real code, it was written correctlY:

 

Ken meant to replace your double quotes with single quotes.

It might work - as it seems like PHP is somehow replacing '&' with the HTML entity.

Link to comment
Share on other sites

Yes Ken, I had some typo when typing the question. But inside my real code, it was written correctlY:

 

Ken meant to replace your double quotes with single quotes.

It might work - as it seems like PHP is somehow replacing '&' with the HTML entity.

 

Hi Poirot, I understood what Ken meant anyway, because before posing question here, my original code was wrapped with single quote and it did not work, as "&" is always change to "&" no matter what kind of quote you use.

 

KC

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.