PS: the full code in the end
i have 2 pages.
php.php
js.php
i sent variables from php.php to js.php by using curl
function js(){
$ch = curl_init();
curl_setopt($ch , CURLOPT_URL ,"http://localhost/js.php");
curl_setopt($ch , CURLOPT_POST , true);
curl_setopt($ch, CURLOPT_POSTFIELDS," ");
curl_setopt($ch , CURLOPT_FOLLOWLOCATION , TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$allaa= curl_exec($ch);
$errorr = curl_error($ch);
echo $allaa;
return $allaa;
}
js.php contain Javascript code
i passed value that i received from first page to Javascript in second page
by this code
var variable=<?php echo json_encode($variable); ?>;
i made some processes on the variable and the result i print it by this code
variable="Hello World";
document.getElementById("result").innerHTML = "!!!"+variable+"!!!";
js.php contain
html code
<p id="result"> </p>
it must the result of Javascript appear in the tag like this
<p id="result">!!!Hello World!!! </p>
in the php.php page i stored the returned value in variable x
and i printed it
$x=js();
$xb = get_string_between($x, "!!!", "!!!");
echo xb;
the result must be
Hello World
but its not its
"+variable+"
how to fix this problem
new edit this is the code
php.php page code
<?php
function get_string_between($string, $start, $end){
$string = ' ' . $string;
$ini = strpos($string, $start);
if ($ini == 0) return '';
$ini += strlen($start);
$len = strpos($string, $end, $ini) - $ini;
return substr($string, $ini, $len);
}
function js(){
////////////////
$ch = curl_init();
curl_setopt($ch , CURLOPT_URL ,"http://localhost/js.php");
curl_setopt($ch , CURLOPT_POST , true);
curl_setopt($ch, CURLOPT_POSTFIELDS,"variable=hello");
curl_setopt($ch , CURLOPT_FOLLOWLOCATION , TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$allaa = curl_exec($ch);
$errorr = curl_error($ch);
echo $allaa;
return $allaa;
}
$ff=js();
echo $xb = get_string_between($ff, "!!!", "!!!!");
?>
js.php page code
<?php
global $variable;
$variable=$_POST['variable'];
?>
<html>
<script>
var variable=<?php echo json_encode($variable); ?>;
variable=variable+" world ";
document.getElementById("result").innerHTML = "!!!"+variable+"!!!!";
</script>
<p id="result"> </p>
</html>