用php中的实际数据替换unicode [英] Replace unicode with actual data in php

查看:46
本文介绍了用php中的实际数据替换unicode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 php 中的实际数据替换 Unicode \ u00a0 .

I want to replace unicode \u00a0 with actual data in php.

示例:< b>排序方式\ u00a0- \ u00a0</b>< a href =" http://pagalworld.com/files/9704/Dil Dhadakne Do(2015)Mp3歌曲/atoz/1.html">A到Z \ u00a0 | \ u00a0</a>< a href ="http://pagalworld.com/files/9704/Dil Dhadakne Do(2015)Mp3 Songs/recent/1.html>最近添加\ u00a0 | \ u00a0</a>< a href =" http://pagalworld.com/files/9704/Dil Dhadakne Do(2015)Mp3 Songs/downloads/1.html">下载次数最多的</a>"

推荐答案

\ u00a0 NO-BREAK SPACE 的转义序列.代码>

要在 PHP 中解码任何 转义序列,可以使用以下功能:

To decode any escape sequence in PHP you can use this function:

function unicodeString($str, $encoding=null) {
    if (is_null($encoding)) $encoding = ini_get('mbstring.internal_encoding');
    return preg_replace_callback('/\\\\u([0-9a-fA-F]{4})/u', create_function('$match', 'return mb_convert_encoding(pack("H*", $match[1]), '.var_export($encoding, true).', "UTF-16BE");'), $str);
}
echo unicodeString($str);
//<b>Sort By - </b><a href="http://pagalworld.com/files/9704/Dil Dhadakne Do (2015) Mp3 Songs/atoz/1.html">A to Z | </a><a href="http://pagalworld.com/files/9704/Dil Dhadakne Do (2015) Mp3 Songs/recent/1.html">Recently Added | </a><a href="http://pagalworld.com/files/9704/Dil Dhadakne Do (2015) Mp3 Songs/downloads/1.html">Most Downloaded</a>


演示:

https://ideone.com/9QtzMO

如果您只需要替换单个 转义序列,请使用:

If you just need to replace a single escape sequence, use:

$str = str_replace("\u00a0", " ", $str);
echo $str;
<b>Sort By - </b><a href="http://pagalworld.com/files/9704/Dil Dhadakne Do (2015) Mp3 Songs/atoz/1.html">A to Z | </a><a href="http://pagalworld.com/files/9704/Dil Dhadakne Do (2015) Mp3 Songs/recent/1.html">Recently Added | </a><a href="http://pagalworld.com/files/9704/Dil Dhadakne Do (2015) Mp3 Songs/downloads/1.html">Most Downloaded</a>

这篇关于用php中的实际数据替换unicode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆