By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,236 Members | 1,598 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,236 IT Pros & Developers. It's quick & easy.

Storing a javascript variable in a php string

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.