2013-07-27 223 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。