值为string的PHP变量在PHP变量中不等于javascript中的html id值?

值为string的PHP变量在PHP变量中不等于javascript中的html id值?

问题描述:

This is my example code

<script>
    var item = "yooow";
    jQuery("#view").html(item);
</script>

<?php  $str_html = '<p id="view"></p>';

     echo $str_html; //it will output "yooow" 
?>

but...

when i'm trying to compare this into another php variable

<?php $str_php ="yooow";

    if($str_html == $str_php)
    {
         echo "true";
    }
    else
    {
        echo "false"; 
    }
?>

but it returns to false

how can they be an equal?

这是我的示例代码 p>

 &lt; script&gt; \  n var item =“yooow”; 
 jQuery(“#view”)。html(item); 
&lt; / script&gt; 
 
&lt;?php $ str_html ='&lt; p id =“view”&gt;  &lt; / p&gt;'; 
 
 echo $ str_html;  //它会输出“yooow”
?&gt; 
  code>  pre> 
 
 

但是...... p>

当我正在尝试 把它比作另一个php变量 p>

 &lt;?php $ str_php =“yooow”; 
 
 if if($ str_html == $ str_php)
 {
  echo“true”; 
} 
 else 
 {
 echo“false”;  
} 
?&gt; 
  code>  pre> 
 
 

但它返回false p>

它们如何相等? p> div>

Better, you give the item value in cookie/session. And, compare the cookie value with $str_php.

<?php session_start(); ?>
<script>
$(document).ready(function(){
    var item = "<?php  echo $_SESSION['html']="yooow"; ?>";
    $("#view").html(item);
});
</script>
<?php  
    $str_html = '<p id="view"></p>';
    $strHtml=$_SESSION['html'];
    $str_php ="yooow";
    if($strHtml == $str_php)
    {
         echo "true";
    }
    else
    {
        echo "false"; 
    }
?>

PHP is run serverside which means it's not aware of any changes you make in the DOM using Javascript.

<script>
var item = "yooow";

Value set only in clinet side, PHP don't know about changes here

jQuery("#view").html(item);   
</script>

<?php  $str_html = '<p id="view"></p>';

WRONG, it will output "<p id="view"></p>"
echo $str_html; //it will output "yooow" ?>

<?php $str_php ="yooow";

Comparing "<p id="view"></p>" and "yoow" and that is not equal!

 if($str_html == $str_php)