473,378 Members | 1,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 2025
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Markus Schuster | last post by:
Hi, I have the following javascript function: <script type="text/javascript"> function HTMLEncode( text ) { text = text.replace(/&/g, "&amp;") ; text = text.replace(/"/g, "&quot;") ;
3
by: RSH | last post by:
Hi, I have a situation where I have created an object that contains fields,properties and functions. After creating the object I attempted to assign it to a session variable so i could retrieve...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.