删除特殊字符

时间:2013-07-27 00:03:58

标签: php special-characters hotlinking

我正在使用以下功能保护链接

 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);

pre encode_html5 $ container

{"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 $ container

$ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ #07b02207006c06107906c06907307402203a05b07b02206306f06d06d06506e07402203a02203003003002d07503906603803207503906606503107503906606503207503306206506207503906606103507503906606106407503906606103807503906606103502202c02206606906c06502203a02206807407407003a02f02f07406507307402e06306f06d02f07507306507207302f06d07507306906302f06106c06207506d07302f03103103003703203003103302f06406e06207206e02e07406f02f03003003002d07503906603803207503906606503107503906606503207503306206506207503906606103507503906606106407503906606103807503906606103502e06d07003302207d02c07b02206306f06d06d06506e07402203a02203003003102d07503906603803307503906606106207503906606103007503906606103207503906606103005f03102202c02206606906c06502203a02206807407407003a02f02f07406507307402e06306f06d02f07507306507207302f06d07507306906302f06106c06207506d07302f03103103003703203003103302f06406e06207206e02e07406f02f03003003102d07503906603803307503906606106207503906606103007503906606103207503906606103005f03102e06d07003302207d02c07b02206306f06d06d06506e07402203a02203003003202d07503906603803307503906606106207503906606103007503906606103207503906606103005f03202202c02206606906c06502203a02206807407407003a02f02f07406507307402e06306f06d02f07507306507207302f06d07507306906302f06106c06207506d07302f03103103003703203003103302f06406e06207206e02e07406f02f03003003202d07503906603803307503906606106207503906606103007503906606103207503906606103005f03202e06d07003302207d02c07b02206306f06d06d06506e07402203a02203003003302d07503906603803307503906606106207503906606103007503906606103207503906606103005f03302202c02206606906c06502203a02206807407407003a02f02f07406507307402e06306f06d02f07507306507207302f06d07507306906302f06106c06207506d07302f03103103003703203003103302f06406e06207206e02e07406f02f03003003302d07503906603803307503906606106207503906606103007503906606103207503906606103005f03302e06d07003302207d02c07b02206306f06d06d06506e07402203a02203003003402d07503906603803307503906606106207503906606103007503906606103207503906606103005f03402202c02206606906c06502203a02206807407407003a02f02f07406507307402e06306f06d02f07507306507207302f06d07507306906302f06106c06207506d07302f03103103003703203003103302f06406e06207206e02e07406f02f03003003402d07503906603803307503906606106207503906606103007503906606103207503906606103005f03402e06d07003302207d02c07b02206306f06d06d06506e07402203a02203003003502d0750390660380330750390660610620750390660610300750390660610320750

1 个答案:

答案 0 :(得分:0)

特别难以理解你想要做什么,但我想我最近遇到了类似的问题。

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

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

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