PHP: Resolving slash / in a string when JSON encoding, the slash is escaped as \/

1. Before modification

problem code

Encoding directly through JSON will cause problems

code

$url = 'SO/'.$fileName;
echo json_encode($url);

Effect

 

2. After solving

Code 

Use json_encode the second argument of the function to disable escaping of slashes JSON_UNESCAPED_SLASHES

$url = 'SO/'.$fileName;
echo json_encode($url, JSON_UNESCAPED_SLASHES);

Effect

Guess you like

Origin blog.csdn.net/weixin_46001736/article/details/134837828