Reputation: 243
I have a jQuery script:
$('[id="a"][f-id="0"]').val(<?php echo $a; ?>)
Now i want to put this script inside a PHP variable $output
and return it via the PHP function.
But those quotes in script are causing lots of syntax errors.
Can anyone make this running?
Upvotes: 1
Views: 74
Reputation: 2837
If I understand correctly, you want to put the Javascript string in your question into a PHP variable. This would look like this:
$myVar = "$('[id=\"a\"][f-id=\"0\"]').val($a)";
The backslashes () before the double quotes are escape characters that let PHP know that you want the actual character " to be in the string, otherwise PHP thinks you want to end the string.
Note that the $a doesn't need to be echoed in this context, because you're not outputting $a, but rather including it in a string.
Upvotes: 2
Reputation: 786
You simply have to put a backslash before the quotes (\). This will tell the PHP compiler that the next sign (the " or ') has to be literal and not the end of the string.
If you wnt to put a backslash, you need "\".
Upvotes: 0