Variables from php to j5

Hello. I start" programing" in p5 few weeks ago. Last week try figure out one problem by reading refference , look tons from YT, and searching at forums.
Small example:

index.php

<?php

   $ble=blebleble
?>

index.js

func. setup
 canvas

 func draw

   CREATEp($BLE);

end of file :slight_smile:

I just want to know , HOW send variables(and values) from php to p5 , and second direction…

I was try evheryting. define by let, var. Using clear js make error.
I train defining on start file, in setup function , and draw.
Ofcourse js is glued in php, and syntax is correct.

In my dreams i see now only big bloody:" Empty and NO DEFINE" :).
please help…

this works:

 <?php

$ble = 7
$ble2 = 'hello'

?>

\<script>
var x = <?php echo $ble?>
console.log(x) // prints 7

var y = "<?php echo $ble2?>" // notice the quotation marks here
console.log(y) // prints hello
\</script>

If you need to pass a string instead of a number, you need to put quotes.
Check this tutorial

Of course you have to write that code in a .php file since it’s the only way to run php (impossible to run php code into a .js or a .html, but you can run javascript code and html in a .php)
AND
you need to run this .php file by a server or localhost.

SyntaxError: expected expression, got ‘<’

I need share this var to js file. Scripts tags in php file is not solution. And left the second way. From js to php…

with quotes i see all what is in quotes. not values from php .
But thanks for trying and link. Morning i will read this chapter.