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
https://forums.phpfreaks.com/topic/44640-crazy-problem-of/
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
https://forums.phpfreaks.com/topic/44640-crazy-problem-of/#findComment-216795
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
https://forums.phpfreaks.com/topic/44640-crazy-problem-of/#findComment-216944
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
https://forums.phpfreaks.com/topic/44640-crazy-problem-of/#findComment-216957
Share on other sites

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.