Calling java script in PHP
Collapse
X
-
Actually, back-ticks, like in other languages, do run the contents as a shell command.actually… no. if you want to ‘execute’ a file you need to load/include it. and that doesn’t return a value…
and backticks are not valid string delimiters.Code:// 4 different ways to include a file include "file.php"; include_once "file.php"; require "file.php"; require_once "file.php";
the only constructs able to return a value are variables, constants, functions, properties and methods (the latter 2 being special cases from to objects)
Code:printf("PHP is located at %s", `which php`); // equivalent of doing printf("PHP is located at %s", shell_exec('which php'));Comment
-
Ok.. Markus... Then what does this return?
Code:`php myfile.php`
A string or ............... ..?
Regards
Dheeraj JoshiComment
-
-
Generally languages have a tendency to print not to return unless we say it so.
Regards
Dheeraj JoshiComment
-
As mentioned before, that won't work because you're not asking PHP to do anything with the string, it's the same as
which obviously will not output anything.Code:<?php "hi, my name is Mark";
Comment
-
yaa my bad Mark...
he need to add an echo before the quotes... I din't see that...
The corrected code will be...
and if $res is holding value one... the javascript will alert "blah blah"Code:<html> <body> <?php $res = `php myfile.php`; switch($res) { case 1: echo "<script language=\"javascript\"> alert('Blah Blah') </script>"; break; case 2: echo "Choice 2"; break; case 3: echo "Choice 3"; break; default:echo "No choice"; break; } ?> </body> </html>Comment
Comment