I'm grabbing some JSON data using file_get_contents and I need to compress it so I can add it as a data attribute on an HTML element in my page. Basically I just need to strip out line breaks, extra spaces or tabs. Everybody seems to suggest using ob_gzhandler. But I can't do that - I don't have control over the modules that are enabled on our production environment. Can anybody suggest a PHP snippet that'll do what I want without ob_gzhandler?
If you want the data written as JSON you could do a simple:
echo json_encode(json_decode($data));
This will strip all whitespaces
您可以用+符号替换空格。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.