pass a binary string from php to JavaScript -
i'm having following php binary string
$buff=chr(1); $buff.=chr(2); $buff.=chr(0); $buff.=chr(0); $buff.=chr(0); $buff.=chr(6); $buff.=chr(1); $buff.=chr(6); $buff.=chr(0); $buff.=chr(192); $buff.=chr(0); $buff.=chr(1) and want pass javascript variable follow var buf=<?=$buff?>; displays error
uncaught syntaxerror: invalid or unexpected token
i tried make chr conversion in javascritp using fromcharcode() charcodeat() tostring(2) still same conversion php chr .
what can solution issue ? put var buf=<?= here ?>? pass php string javascript code or how can have equivalent conversion aschr in javascript . solutions have found far have been stated above none of them worked !
help please
thanks
you possibly not enclosing javascript in script tag? want make sure put variable value in quotes.
<?php $buff=chr(1); $buff.=chr(2); $buff.=chr(0); $buff.=chr(0); $buff.=chr(0); $buff.=chr(6); $buff.=chr(1); $buff.=chr(6); $buff.=chr(0); $buff.=chr(192); $buff.=chr(0); $buff.=chr(1) ?> <script> var buf="<?=$buff ?>"; console.log(buf); </script>
Comments
Post a Comment