View Single Post
  #3 (permalink)  
Old November 30th, 2005, 10:16 PM
richard.york's Avatar
richard.york richard.york is offline
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Not exactly. You have to keep in mind that PHP runs on the server, and JavaScript on the client-side. So sharing may not happen in the way you may expect. JavaScript can only send variables to PHP via POST (as in a form submission), GET (form submission, or URL query string), or COOKIE. PHP can create and output JavaScript, so you would merely generate JavaScript as you would HTML to send PHP variables to JavaScript. For example:

Code:
<?php

$hello = 'Hello, world!';

echo "<script type='text/javascript'>\n".
     "    var \$hello = '{$hello}';\n".
     "    alert(\$hello);\n".
     "</script>\n";

?>
HTH!

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
Reply With Quote