dpus81500574 2012-09-12 13:18
浏览 77
已采纳

通过我的URL解码一个字节编码的字符串

We have a PHP site on Zend Framework with a backend Postgresql database. Our primary character encoding is UTF-8.

I just checked our error log and found a strange entry. My URL is as follows: www.mydomain.com/schuhe-für-breite-füsse

however someone (or maybe a bot) has tried to access this URL as follows: www.mydomain.com/schuhe-f\xc3\xbcr-breite-f\xc3\xbcsse/

It's the first time I've seen something like the above. Two things are happening on my page: 1) The above URL is queried against our CMS. This works fine for some reason, I think Postgresql reaslises it is byte-encoded and then converts it back when tried to find this SEF URL in our database.

2) An Ajax request is made on the page, passing the same SEF URL. This fails. I believe the slashes are causing a problem on Javascript.

To avoid this I want to decode any URL that is encoded like this. However a quick test of the following code did not decode anything for me :(

$landing_sef_url = $this->_getParam('landing_sef_url');
$utf8=html_entity_decode($landing_sef_url);
$iso8859=utf8_decode($utf8);
$test3 = html_entity_decode($landing_sef_url, 1, "ISO-8859-1");
$test4 = urldecode($landing_sef_url);

echo utf8_decode("$landing_sef_url");
echo "<br/><br/>";
die($landing_sef_url . " -- $utf8 -- $iso8859 <br/>$test3<br/>$test4");

I found the above via various posts online but they all print back the same result - schuhe-f\xc3\xbcr-breite-f\xc3\xbcsse

Any help would be MUCH appreciated. Many thanks!

  • 写回答

1条回答 默认 最新

  • doudiemei2013 2012-09-12 13:54
    关注

    This method seems to do what you're looking for:

    http://li.php.net/manual/en/function.stripcslashes.php

    But if you're just looking to unescape \x## sequences, you could also do this with a fairly simple regular expression.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么