So I have this code:
else {
$strlen = json_encode(strlen($_POST['message']));
?>
<script language="javascript" type="text/javascript">
var length = <?php echo $strlen ?>
alert("Your message was too long (max 255 chars), yours was " + length);
</script>
<?php
echo "Your message was too long (max 255 chars)";
echo "Yours was " . $strlen . " charachters long";
}
... and It will just not display the alert box with the value of the actual strlen of the string.
The "Yours was $strlen charchters long" works fine.
I have also tried removing json_encode(), that did not either.
json_encodefavors a two-dimensional array which holds thekeyandvalueof a JSON list/dictionary.vardeclaration. JavaScript has automatic-semi-colon-insertion, and should not blow up if you forget one. As suggested above, you really should paste in the JS output.json_encodedoes not "prefer" any such thing: us1.php.net/json_encode