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

pre 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 $container

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

1 回答 1

0

很难具体理解您要做什么,但我想我最近遇到了类似的问题。

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

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

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

于 2013-08-22T00:04:10.510 回答