I have below code in php  &lt;? php      $articleContent = "  Blah ..                         The game is on                          Foo "; ?&gt;   Also I have below JavaScript Code Also  &lt;script&gt;    var articleContent = "{$articleContent}";  // from php        /* I WANT TO USE THIS  articleContent variable , but it cannot take it , it displays a ILLEGAL token error due to multi line string !*/ &lt;/script&gt;
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.
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.
88330
I've seen some people using void operator in their code. I have also seen this in href attributes: javascript:void(0) which doesn't seem any better than javascript:;  So, what is the justification of using the void operator?
23800
wondered if you could help me please? I have node in xml that is as followed  $LOG: 08880xbpnd $ fhdsafidsfsd df sd fsd f sd fsd  I was wondering is there anyway to make all the text go on to one line so that it then can be passsed through to a javascript function? so it would turn out like this   $LOG: 08880xbpnd $fhdsafidsfsddfsdfsdfsdfsd
7083
I need to  an object to . I'm using . Is there a "standard" way to do this?  My specific situation: I have an array defined as shown below:  var countries = new Array(); countries[0] = 'ga'; countries[1] = 'cd'; ...   and I need to turn this into a string to pass to  like this:  $.ajax({     type: "POST",     url: "Concessions.aspx/GetConcessions",     data: "{'countries':['ga','cd']}", ...
16373
How do I pass have a Javascript script request a PHP page and pass data to it? How do I then have the PHP script pass data back to the Javascript script?  client.js:  data = {tohex: 4919, sum: [1, 3, 5]}; // how would this script pass data to server.php and access the response?   server.php:  $tohex = ... ; // How would this be set to data.tohex? $sum = ...; // How would this be set to data.sum? // How would this be sent to client.js? array(base_convert($tohex, 16), array_sum($sum))
32799
I got feedback from security guy and he pointed out that I should use proper escaping of user input in my code. So I've done some research and found escaping functions.  What’s the difference between them? When should I use esc_html() and when esc_attr()? And when should I use these functions with _e() at the end?
91040
I wrote a PHP code like this  $site="http://www.google.com"; $content = file_get_content($site); echo $content;   But when I remove "http://" from $site I get the following warning:     Warning:   file_get_contents(www.google.com)   [function.file-get-contents]: failed   to open stream:   I tried try and catch but it didn't work.
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;
89206
I am getting error:     The argument 2 of the "JSON_VALUE or JSON_QUERY" must be a string literal   ...while trying to pass variable as parameter to JSON_QUERY function. Please help me to resolve it.  DECLARE @cnt INT = 1; DECLARE @cnt_total INT = 1; DECLARE @json NVARCHAR(MAX); DECLARE @json1 NVARCHAR(MAX); declare @str  VARCHAR(200);  WHILE @cnt &lt;= 10 BEGIN     set @str = '$.Seasons[0].Products['+convert(varchar,@cnt)+'].ProductChannels';     set @str = char(39) +@str+ char(39);     PRINT @STR     select @json = json_query(jfile,@STR) from Import.tstjson; --MORE CODE         SET @cnt = @cnt + 1; END   Sample data:  {   "Seasons": [     {       "Season": "12321231",       "Products": [         {           "ProductId": "211",           "ProductChannels": [             {               "ChannelId": 1,               "WeekQuantities": []             }           ],           "ccc": 3,           "Tttt": 4         }       ]     }   ] }
94609
I'm working at an app which would make a POST ajax request to a PHP script on my server. The script would query the database and return a row of records, as an array. (One array for each row, containing elements such as id, title, etc). I then want to use json_encode() to encode this array, and pass it back to the javascript which will use it to display the records.  1) How can I return the JSON encoded string to the javascript? 2) How will the javascript loop through the rows and access their fields?
836
I'm writing a php program that pulls from a database source. Some of the varchars have quotes that are displaying as black diamonds with a question mark in them (�, , I assume from Microsoft Word text).  How can I use php to strip these characters out?
48142
A user may not post a  link if the user doesn't also post some code with it.  I recently learned that .  Why isn't this ban in place with all the other sites similar to JS/PHPFiddle, like , , , ,  etc.?
19393
How to restrict the maximum number of characters that can be entered into an HTML &lt;textarea&gt;? I'm looking for a cross-browser solution.
104592
I am running some script which passing the string argument and I want to do if else statement shown as below:  if [ $1 != '' ] &amp;&amp; [ $2 != '' ] then      do something.....   but it shown Error too many argument. Why?
28523
Here's a PHP example of mine. Can anyone find a shorter/easier way to do this?  &lt;? foreach($posts as $post){?&gt;     &lt;div class="&lt;?=($c++%2==1)?‘odd’:NULL?&gt;"&gt;         &lt;?=$post?&gt;     &lt;/div&gt; &lt;? }?&gt;  &lt;style&gt;     .odd{background-color:red;} &lt;/style&gt;   Examples in other languages would be fun to see as well.
82950
I'm in the process of moving an application from PHP to Java and there is heavy use of regular expressions in the code.  I've run across something in PHP that doesn't seem to have a java equivalent:  preg_replace_callback()   For every match in the regex, it calls a function that is passed the match text as a parameter.  As an example usage:  $articleText = preg_replace_callback("/\[thumb(\d+)\]/",'thumbReplace', $articleText); # ... function thumbReplace($matches) {    global $photos;    return "&lt;img src=\"thumbs/" . $photos[$matches[1]] . "\"&gt;"; }   What would be the ideal way to do this in Java?