2013-07-27 51 views
3

我保护链路具有以下功能删除特殊字符

function encode_html5($str){ 
     return '#'.preg_replace("/0{1}([0-9a-f]{3})/i", "$1", implode("", unpack("H*", iconv("UTF-8", "UTF-16BE", $str)))); 
} 

的问题产生一些特殊的字符,我打开文件,vim :set list,在开始处有$然后很多@终于#这是我的链接应该开始的地方。

我已经尝试了很多不同的东西,但似乎没有任何工作。我已经试过:

$container = encode_html5($container); 
$container = preg_replace('/[^a-zA-Z0-9_ %\[\]\.\(\)%&-]/s', '', $container); 
$container = str_replace('$', '', $container); 
$container = str_replace('#', '', $container); 
$container = htmlentities($container); 
$container = preg_replace("/[^0-9]/",'', $container); 

预encode_html5 $容器

{"playlist":[{"comment":"000-u9f82u9fe1u9fe2u3bebu9fa5u9fadu9fa8u9fa5","file":"http://test.com/users/music/albums/11072013/dnbrn.to/000-u9f82u9fe1u9fe2u3bebu9fa5u9fadu9fa8u9fa5.mp3"},{"comment":"001-u9f83u9fabu9fa0u9fa2u9fa0_1","file":"http://test.com/users/music/albums/11072013/dnbrn.to/001-u9f83u9fabu9fa0u9fa2u9fa0_1.mp3"},{"comment":"002-u9f83u9fabu9fa0u9fa2u9fa0_2","file":"http://test.com/users/music/albums/11072013/dnbrn.to/002-u9f83u9fabu9fa0u9fa2u9fa0_2.mp3"},{"comment":"003-u9f83u9fabu9fa0u9fa2u9fa0_3","file":"http://test.com/users/music/albums/11072013/dnbrn.to/003-u9f83u9fabu9fa0u9fa2u9fa0_3.mp3"},{"comment":"004-u9f83u9fabu9fa0u9fa2u9fa0_4","file":"http://test.com/users/music/albums/11072013/dnbrn.to/004-u9f83u9fabu9fa0u9fa2u9fa0_4.mp3"},{"comment":"005-u9f83u9fabu9fa0u9fa2u9fa0_5","file":"http://test.com/users/music/albums/11072013/dnbrn.to/005-u9f83u9fabu9fa0u9fa2u9fa0_5.mp3"},{"comment":"006-u9f83u9fabu9fa0u9fa2u9fa0_6","file":"http://test.com/users/music/albums/11072013/dnbrn.to/006-u9f83u9fabu9fa0u9fa2u9fa0_6.mp3"},{"comment":"007-u9f83u9fabu9fa0u9fa2u9fa0_7","file":"http://test.com/users/music/albums/11072013/dnbrn.to/007-u9f83u9fabu9fa0u9fa2u9fa0_7.mp3"},{"comment":"008-u9f83u9fabu9fa0u9fa2u9fa0_8","file":"http://test.com/users/music/albums/11072013/dnbrn.to/008-u9f83u9fabu9fa0u9fa2u9fa0_8.mp3"},{"comment":"009-u9f83u9fabu9fa0u9fa2u9fa0_9","file":"http://test.com/users/music/albums/11072013/dnbrn.to/009-u9f83u9fabu9fa0u9fa2u9fa0_9.mp3"},{"comment":"010-u9f83u9fabu9fa0u9fa2u9fa0_10","file":"http://test.com/users/music/albums/11072013/dnbrn.to/010-u9f83u9fabu9fa0u9fa2u9fa0_10.mp3"},{"comment":"011-u9f83u9fabu9fa0u9fa2u9fa0_11", 
... 

后encode_html5 $容器

$ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ #07b02207006c06107906c06907307402203a05b07b02206306f06d06d06506e07402203a02203003003002d07503906603803207503906606503107503906606503207503306206506207503906606103507503906606106407503906606103807503906606103502202c02206606906c06502203a02206807407407003a02f02f07406507307402e06306f06d02f07507306507207302f06d07507306906302f06106c06207506d07302f03103103003703203003103302f06406e06207206e02e07406f02f03003003002d07503906603803207503906606503107503906606503207503306206506207503906606103507503906606106407503906606103807503906606103502e06d07003302207d02c07b02206306f06d06d06506e07402203a02203003003102d07503906603803307503906606106207503906606103007503906606103207503906606103005f03102202c02206606906c06502203a02206807407407003a02f02f07406507307402e06306f06d02f07507306507207302f06d07507306906302f06106c06207506d07302f03103103003703203003103302f06406e06207206e02e07406f02f03003003102d07503906603803307503906606106207503906606103007503906606103207503906606103005f03102e06d07003302207d02c07b02206306f06d06d06506e07402203a02203003003202d07503906603803307503906606106207503906606103007503906606103207503906606103005f03202202c02206606906c06502203a02206807407407003a02f02f07406507307402e06306f06d02f07507306507207302f06d07507306906302f06106c06207506d07302f03103103003703203003103302f06406e06207206e02e07406f02f03003003202d07503906603803307503906606106207503906606103007503906606103207503906606103005f03202e06d07003302207d02c07b02206306f06d06d06506e07402203a02203003003302d07503906603803307503906606106207503906606103007503906606103207503906606103005f03302202c02206606906c06502203a02206807407407003a02f02f07406507307402e06306f06d02f07507306507207302f06d07507306906302f06106c06207506d07302f03103103003703203003103302f06406e06207206e02e07406f02f03003003302d07503906603803307503906606106207503906606103007503906606103207503906606103005f03302e06d07003302207d02c07b02206306f06d06d06506e07402203a02203003003402d07503906603803307503906606106207503906606103007503906606103207503906606103005f03402202c02206606906c06502203a02206807407407003a02f02f07406507307402e06306f06d02f07507306507207302f06d07507306906302f06106c06207506d07302f03103103003703203003103302f06406e06207206e02e07406f02f03003003402d07503906603803307503906606106207503906606103007503906606103207503906606103005f03402e06d07003302207d02c07b02206306f06d06d06506e07402203a02203003003502d0750390660380330750390660610620750390660610300750390660610320750 
+1

使用'htmlentities()'有什么问题? – Havenard

+0

我的链接是json格式 – rabotalius

+1

你可以发布'$ container'的原始值,你想得到什么,以及你实际得到的是什么? – Barmar

回答

0

这一点很难以具体了解你正在尝试做的,但我想最近我有类似的问题。

尝试http://php.net/manual/en/function.htmlspecialchars.php并且它在数据传输之前就与解码功能相关联。

您也可以在使用json_encode之后尝试html_entity_decode。

我提供的最后一件事是在回声之前对您的字符串进行json_encode。