I am currently working on a calendar application that I made using javascript but need to get some values from a MYSQL database so I used PHP to do all that business. So my question was since PHP is a server side scripting language and javascript is a client side scripting language, when PHP parses the Javascript is the code read through my server instead of using the client to do some of the processing?
I could be completely wrong about all of this I was just curious and the only way to learn is to ask questions
Parsing Javascript Using PHP
Moderator: General Moderators
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Parsing Javascript Using PHP
If your page is PHP then it will be parsed for PHP and the result sent to the browser where the JS will be interpreted. So given this:
Then this will be sent to the browser:
[text]<script type="text/javascript">
alert('Welcome!');
</script>[/text]
HTH
Code: Select all
<?php
$message = 'Welcome!';
?>
<script type="text/javascript">
alert('<?php echo $message; ?>');
</script>[text]<script type="text/javascript">
alert('Welcome!');
</script>[/text]
HTH
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: Parsing Javascript Using PHP
But if I am calling the 'javascript' like this:
and all the javascript lines are called using:
With this is the php module doing all the work on my server or is the client getting some of the work load?
Code: Select all
<script language="JavaScript" src="js/calendar.php"></script>Code: Select all
echo "function(){
//whatever code I have written
";
$con(mysql_connect(.....);
// more php then back to javascript
echo "function(){
.......- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Parsing Javascript Using PHP
Anything in PHP tags will be parsed and executed by PHP (db queries, echos etc.) and the result passed to the browser. At that point whatever pure javascript code is there will be executed in the browser.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: Parsing Javascript Using PHP
Oh kk. Well that makes sense then. I was just thinking about how if the php parsed the javascript and actually executed it then sent it to the browser how that might be a bit of an issue. But if php parses it and then sends it to the browser once it is parsed then there shouldnt be any major issues
Re: Parsing Javascript Using PHP
PHP doesn't parse Javascript or any language other than PHP.
When you have a file with a .php extension, the PHP interpreter looks through it for "<?php" (or "<?" if shorttags are on). Anything between <?php and ?> is treated as PHP code. Period. If Javascript is in there, it had better be in a string, or the PHP interpreter is not going to know what to do with it.
As far as the PHP interpreter is concerned, in any given file there is PHP code and ... everything else. Only PHP code is parsed. Everything else is just passed through as-is.
When you have a file with a .php extension, the PHP interpreter looks through it for "<?php" (or "<?" if shorttags are on). Anything between <?php and ?> is treated as PHP code. Period. If Javascript is in there, it had better be in a string, or the PHP interpreter is not going to know what to do with it.
As far as the PHP interpreter is concerned, in any given file there is PHP code and ... everything else. Only PHP code is parsed. Everything else is just passed through as-is.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.