I'm trying to pass a php var that is a string using Javascript, but in the final result the string gets cmmented in html. Here's my code:  PHP:  $txtVar = "My text";   JavaScript:   var txt = '&lt;?php echo $txtVar; ?&gt;'; document.getElementById('MyDiv').innerHTML = txt;   HTML(result):  &lt;div id="MyDiv"&gt;&lt;!--?php echo $txtVar ; ?--&gt;&lt;/div&gt;   I just want the string value to be printed in my html, withou the comments ()
8481
What is the easiest way to encode a PHP string for output to a JavaScript variable?  I have a PHP string which includes quotes and newlines.  I need the contents of this string to be put into a JavaScript variable.  Normally, I would just construct my JavaScript in a PHP file, à la:  &lt;script&gt;   var myvar = "&lt;?php echo $myVarValue;?&gt;"; &lt;/script&gt;   However, this doesn't work when $myVarValue contains quotes or newlines.
90347
How do i dynamically assign a name to a php object?  for example how would i assign a object to a var that is the id of the db row that i am using to create objects.  for example   $&lt;idnum&gt;= new object();   where idnum is the id from my database.
85912
I am using PHP and JavaScript. My JavaScript code contains a function, get_data():  function get_Data(){     var name;     var job;     .....      return buffer; }   Now I have PHP code with the following.  &lt;?php     $i=0;     $buffer_data;      /* Here I need to get the value from JavaScript get_data() of buffer;        and assign to variable $buffer_data. */ ?&gt;   How do I assign the JavaScript function data into the PHP variable?
45221
&gt; echo "hi" hi &gt; VAR='echo "hi"' &gt; $VAR "hi"   Why is the output of the above commands different?  A similar thing occurs with single quotes:  &gt; VAR="echo 'hi'" &gt; $VAR &gt; 'hi'
85935
I've got a multidimensional associative array which includes an elements like  $data["status"] $data["response"]["url"] $data["entry"]["0"]["text"]   I've got a strings like:  $string = 'data["status"]'; $string = 'data["response"]["url"]'; $string = 'data["entry"]["0"]["text"]';   How can I convert the strings into a variable to access the proper array element? This method will need to work across any array at any of the dimensions.
7928
I wanted to add custom JavaScript code on certain nodes. I have written this code in the html.tpl.php template, but this doesn't work. (donate is the path alias for a node.) &lt;?php if(arg(0) == 'DONATE'): ?&gt;   &lt;script&gt;     (function() {       // ...     );   &lt;/script&gt; &lt;?php endif; ?&gt;
103558
Is there an inbuilt PHP function to replace multiple values inside a string with an array that dictates exactly what is replaced with what?  For example:  $searchreplace_array = Array('blah' =&gt; 'bleh', 'blarh' =&gt; 'blerh'); $string = 'blah blarh bleh bleh blarh';   And the resulting would be: 'bleh blerh bleh bleh blerh'.
114665
When I want to execute a php file it's displayed as text in my browser.  I have a VPS at Hostinger I installed Ubuntu 18.04 with Webmin and LAMP(installed automatically).  I checked the installation see below.  apache2 - v and php -v gives me: Apache/2.4.29 and PHP 7.2.24-0ubuntu0.18.04.6  So everything seem to be installed correctly.  My default folder is /var/www/html/ I do not us short tag in my code.  I try to lunch a file called phpinfo.php with content:  &lt;?php phpinfo(); ?&gt;   And plain text appear on the page.  If the file begin with html code it's correctly rendered, even with a .php file. But the php part is not executed. e.g:  &lt;!DOCTYPE html&gt; &lt;html lang="en" dir="ltr"&gt;   &lt;head&gt;     &lt;meta charset="utf-8"&gt;     &lt;title&gt;&lt;/title&gt;   &lt;/head&gt;   &lt;body&gt;     &lt;h1&gt;Hello&lt;/h1&gt;   &lt;/body&gt; &lt;/html&gt;  &lt;?php phpinfo(); ?&gt;   Render :  Hello  But  &lt;?php phpinfo(); ?&gt;  &lt;!DOCTYPE html&gt; &lt;html lang="en" dir="ltr"&gt;   &lt;head&gt;     &lt;meta charset="utf-8"&gt;     &lt;title&gt;&lt;/title&gt;   &lt;/head&gt;   &lt;body&gt;     &lt;h1&gt;Hello&lt;/h1&gt;   &lt;/body&gt; &lt;/html&gt;   Render the code as plain text.
71838
I created file node--my_content_type.tpl.php, where I'd like to print the username as string. I tried the following code, but unfortunately it doesn't work. How can I do it?  &lt;?php    print $name; ?&gt;
12917
I would like to use variable substitution on a particular string that I access via a command. For example, if I copy something into my clipboard, I can access it like this.  $ xclip -o -selection clipboard Here's a string I just copied.   If I assign it to a variable, then I can do variable substitution on it.  $ var=$(xclip -o -selection clipboard) $ echo $var Here's a string I just copied. $ echo ${var/copi/knott} Here's a string I just knotted.   However, is there a way to do variable substitution without assigning it to a variable? Conceptually, something like this.  $ echo ${$(xclip -o -selection clipboard)/copi/knott} bash: ${$(xclip -o -selection clipboard)/copi/knott}: bad substitution   This syntax fails, because var should be a variable name, not a string.
77877
I know PHP is usually used for web development, where there is no standard input, but PHP claims to be usable as a general-purpose scripting language, if you do follow it's funky web-based conventions. I know that PHP prints to stdout (or whatever you want to call it) with print and echo, which is simple enough, but I'm wondering how a PHP script might get input from stdin (specifically with fgetc(), but any input function is good), or is this even possible?
29690
I'd like to capture the output of  to a string.  The PHP documentation says;     As with anything that outputs its result directly to the browser, the  can be used to capture the output of this function, and save it in a string (for example).   What would be an example of how that might work?  print_r() isn't a valid possibility, because it's not going to give me the information that I need.
2361
Given a string of JSON data, how can I safely turn that string into a JavaScript object?  Obviously I can do this unsafely with something like:  var obj = eval("(" + json + ')');   but that leaves me vulnerable to the JSON string containing other code, which it seems very dangerous to simply eval.
114670
I recall reviewing someone else's PHP code once and he had a function or class method that rolled all GET and POST variables into a single plain old object that could then be passed around. If the same name-value pair appeared in both GET and POST, POST would win.  Is there a well-coded PHP add-on out there of any sort that does exactly this?
111204
I have three strings:  $str1 = "abc"; $str2 = "def"; $str3 = "ghi";  I can get the value of all of them like this:  echo "$str1$str2$str3";  But I heard there is a way to join them together, so I can echo all of them without quotes.
35211
I have an odd problem...I'm using a documentation generator which generates a lot of output like docs/foo.php.html. It's XHTML, and thus contains &lt;?xml...&gt; tags at the beginning of file. The problem is, Apache has somehow decided to run it through the PHP interpreter, even though ".php" appears in the middle of the filename, and not at the end. This, in turn, triggers a PHP error, because it sees "&lt;?" as the command to start executing PHP code, and immediately gets confused by the "xml..." which follows it.  How do I configure Apache to ONLY execute .php files and not .php.html files? The string "php.html" does not appear explicitly anywhere in my Apache config files. There is a line "AddHandler php5-script .php", but I don't see how that would also include ".php.html" files.
26387
I have a text file in the root of my web app  and I'd like to load it into a variable in javascript.. in groovy I would do this:  def fileContents = 'http://localhost/foo.txt'.toURL().text; println fileContents;   How can I get a similar result in javascript?