Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As has been mentioned by others, a forward slash is not a special character inside a string, in PHP or in Javascript (and since JSON is derived from Javascript it follows the same rules for string interpolation). However if you were reading some JSON, you could be forgiven for thinking that it is (although you should <em>always</em> RTM ;-) ).</p> <p>The reason you think you need to escape the slash is due to a subtle difference in the way PHP and Javascript interpolate superfluous forward slashes. Consider the following string declaration, valid in both PHP and Javascript:</p> <pre><code>"AC\/DC" </code></pre> <p>In PHP, the extra backslash is treated as a literal, so:</p> <pre><code>echo "AC\/DC"; // outputs AC\/DC </code></pre> <p>In Javascript, the extra backslash is dropped, so:</p> <pre><code>console.log("AC\/DC"); // logs AC/DC </code></pre> <p>JSON mandates the escaping of forward slashes, but <a href="http://php.net/json-encode" rel="nofollow noreferrer"><code>json_encode()</code></a> will take care of this escaping for you. You do not need to add the backslashes to the string yourself. And because of the difference in the way these additional backslashes are interpolated, you cannot simply take a JSON string and drop it into your PHP source - because it will will be interpretted as a different value.</p> <p><a href="http://php.net/json-encode#refsect1-function.json-encode-changelog" rel="nofollow noreferrer">Since PHP 5.4.0</a> you can supply the <code>JSON_UNESCAPED_SLASHES</code> flag to <code>json_encode()</code> in PHP to prevent it from adding the backslashes. However this is unnecessary and may cause a strict JSON parser to reject the data.</p> <p>So to sum up, the correct way to declare your string in PHP is:</p> <pre><code>$path["file_name"] = "www.119.com/assets/demo/large/".$row["file_name"]; </code></pre> <p>As a side note, you probably also what to include <code>http://</code> at the beginning of the string and pass <code>$row['file_name']</code> through <a href="http://php.net/urlencode" rel="nofollow noreferrer"><code>urlencode()</code></a> as well, since the data appears to be a URL:</p> <pre><code>$path["file_name"] = "http://www.119.com/assets/demo/large/".urlencode($row["file_name"]); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload