# Variables from php to j5

**URL:** <https://discourse.processing.org/t/variables-from-php-to-j5/20153>\
**Category:** Coding Questions\
**Created:** [April 25, 2020, 10:38pm UTC](https://discourse.processing.org/t/variables-from-php-to-j5/20153 "2020-04-25T22:38:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![goorny](https://avatars.discourse-cdn.com/v4/letter/g/aeb1de/32.png) [@goorny](https://discourse.processing.org/u/goorny)\
**Post date:** [April 25, 2020, 10:38pm UTC](https://discourse.processing.org/t/variables-from-php-to-j5/20153/1 "2020-04-25T22:38:27Z")

</div>

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

```auto
<?php

   $ble=blebleble
?>

```

index.js

```auto
func. setup
 canvas

 func draw

   CREATEp($BLE);

```

end of file 🙂

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…

---

<div class="post-metadata">

**Author:** ![alexalex25](https://avatars.discourse-cdn.com/v4/letter/a/c68b51/32.png) [@alexalex25](https://discourse.processing.org/u/alexalex25)\
**Post date:** [April 25, 2020, 11:30pm UTC](https://discourse.processing.org/t/variables-from-php-to-j5/20153/2 "2020-04-25T23:30:32Z")

</div>

this works:

```auto
 <?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](https://www.dyn-web.com/tutorials/php-js/scalar.php)

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.

---

<div class="post-metadata">

**Author:** ![goorny](https://avatars.discourse-cdn.com/v4/letter/g/aeb1de/32.png) [@goorny](https://discourse.processing.org/u/goorny)\
**Post date:** [April 25, 2020, 11:51pm UTC](https://discourse.processing.org/t/variables-from-php-to-j5/20153/3 "2020-04-25T23:51:05Z")

</div>

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.
