PHP json_encode () does not escape slash

json_encode () JSON encoding of variables, in the form of a string of JSON, or returns false failure. Once again a link address JSON-encoded, the returned string is always the problem, found in the </a> slash is escaped, leading to abnormal link structure. Read PHP documents, I found json_encode () The second parameter can be set to JSON_UNESCAPED_SLASHES value, then you can solve the problem perfectly. Details are as follows:

$str = "you can click <a href = '/login'>here</a>";
var_dump(json_encode($str,JSON_UNESCAPED_SLASHES));
var_dump(json_encode($str));
string(43) ""you can click here"" string(45) ""you can click here<\/a>"" 

 

Guess you like

Origin blog.csdn.net/uvyoaa/article/details/83901280