I have the following piece of code which I partly got from another thread in SO:
<?php
header('Content-Type: text/html; charset=ISO-8859-1');
$origadd = $_SESSION["OriginAdd"] // $_SESSION["OriginAdd"] has a value "rueFrédéricMistral";
echo $origadd; // This displays rueFrédéricMistral
?>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript">
var source = <?php echo json_encode($origadd); ?>;
alert(source); // This displays null
</script>
</head>
....
....
</html>
As I have mentioned in the comments, the echo statement gives me the original string. However, the alert box in JS gives me a null value because of which the subsequent code is failing.
json_encodelike that. If you usevar source = '<?php echo $origadd; ?>';as my example and quoting it (something you didn't do), you will see your data is there. There are quite a few examples of this on the web. One of which stackoverflow.com/questions/40999171/json-encode-alert-message and stackoverflow.com/questions/18932686/…json_encodelike that? It's in fact the preferred way to use it in a case like this.var source = ...line looks like exactly. Also show us how that string is encoded exactly withecho bin2hex($origadd).