how to passing values from php to javascript to html to php -


ps: full code in end

i have 2 pages.

php.php

js.php

i sent variables php.php js.php 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 received first page javascript in second page

by code

 var variable=<?php echo  json_encode($variable); ?>; 

i made processes on variable , result print code

 variable="hello world";  document.getelementbyid("result").innerhtml = "!!!"+variable+"!!!"; 

js.php contain

html code

 <p id="result"> </p> 

it must result of javascript appear in tag this

 <p id="result">!!!hello world!!! </p> 

in php.php page stored returned value in variable x

and printed

 $x=js();   $xb = get_string_between($x, "!!!", "!!!");  echo xb; 

the result must be

hello world

but not

"+variable+"

how fix problem

new edit 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> 

i think script js.php not interpreted on server side , script plain text between "!!!" "+variable+".


Comments