i have this source:
<div id="tst"></div>
<?php
function test($txt) {
if ($txt == "aa") {
return "true!";
}
return "false!";
}
?>
<script>
document.getElementById('tst').innerHTML = "<?php echo test('%s'); ?>".replace("%s","aa");
</script>
in this line : if ($txt == "aa") {
why the 'if' show me false? (meaning: aa != aa)
Something else I noticed, that if i use 0 instead of aa (in the JS and in the php source), and in the php source i use at "0" (with apostrophes), the 'if' show me "false" (meaning: 0 != 0). (EX.1)
but if i use at 0 (with no apostrophes) in the php source, the if show me "true" (meaning 0 == 0). (EX.2)
the ex.2, is the only that works fine!
Someone understand what the problem is? and how can i fix it?
EX.1:
<div id="tst"></div>
<?php
function test($txt) {
if ($txt == "0") { // with apostrophes
return "true!";
}
return "false!";
}
?>
<script>
document.getElementById('tst').innerHTML = "<?php echo test('%s'); ?>".replace("%s","0");
</script>
EX.2:
<div id="tst"></div>
<?php
function test($txt) {
if ($txt == 0) { // with no apostrophes
return "true!";
}
return "false!";
}
?>
<script>
document.getElementById('tst').innerHTML = "<?php echo test('%s'); ?>".replace("%s","0");
</script>