PHP echo javascript with PHP variable -


i displaying javascript via php echo:

        echo 'var currentinvoicedatajson = <?php echo json_encode($yeardata_invoices[$currentyear] ); ?>;'; 

however uncaught syntaxerror: unexpected token < error infer related second

how can resolved , there other possibilities?

some expert advise appreciated.

that code ends invalid javascript code.

here's happens:

your server echoes string:

echo 'var currentinvoicedatajson = <?php echo json_encode($yeardata_invoices[$currentyear] ); ?>;'; 

your browser has:

var currentinvoicedatajson = <?php echo json_encode($yeardata_invoices[$currentyear] ); ?>; 

once php script finishes running , echoes first string, php cannot process inner echo.


what do:

$data = json_encode($yeardata_invoices[$currentyear]); echo 'var currentinvoicedatajson = ' . $data . ';'; 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -