469,642 Members | 1,197 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,642 developers. It's quick & easy.

Storing a javascript variable in a php string

Hi,

I have the following javascript function:

<script type="text/javascript">

function HTMLEncode( text )
{
text = text.replace(/&/g, "&amp;") ;
text = text.replace(/"/g, "&quot;") ;
text = text.replace(/</g, "&lt;") ;
text = text.replace(/>/g, "&gt;") ;
text = text.replace(/'/g, "'") ;

return text ;
}

</script>

Now i want to store the content of 'text' in a php string.
Is that possible?

Thanks, Max
Jul 7 '06 #1
2 1892
Ivo
"Markus Schuster" wrote
I have the following javascript function:

function HTMLEncode( text )
{
<snip>
return text ;
}

Now i want to store the content of 'text' in a php string.
Is that possible?
Certainly, but remember the JavaScript and PHP run on different computers,
one with the client, one on the server. You need to communicate the
Javascript string to the server by POSTing it in a form, or append it to an
URL as query string. Then PHP can it up from there. This usually involves a
page reload, but using AJAX overcomes that.
How is your function HTMLEncode called? By what sort of event?
ivo
Jul 7 '06 #2
Ivo said the following on 7/7/2006 3:21 AM:
"Markus Schuster" wrote
>I have the following javascript function:

function HTMLEncode( text )
{
<snip>
> return text ;
}

Now i want to store the content of 'text' in a php string.
Is that possible?

Certainly, but remember the JavaScript and PHP run on different computers,
one with the client, one on the server. You need to communicate the
Javascript string to the server by POSTing it in a form, or append it to an
URL as query string. Then PHP can it up from there. This usually involves a
page reload, but using AJAX overcomes that.

myImage = new Image()
myImage.src = "somePHPFile.php?" + JSString

No reload required, nor "AJAX"

The only time you need to do a reload or anything different is if you
want to do something with the output of somePHPFile.php and that still
doesn't require a reload or AJAX.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jul 7 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.