dqwh1202 2012-03-24 08:03
浏览 31

php url to absolute function现在可以使用空格和阿拉伯语字符

i have these functions url_to_absolute its work good but not work if the image url has space or arabic chars

this working example

<?php
    require_once('url_to_absolute.php');
    $url = 'http://site.com/news/view.aspx?id=23032012';
    echo url_to_absolute($url, '/uploadedimages/Sections/Politics/Arabic_World/original/Administrative-detention.jpg'), "
";
    ?>
look here if we have space in "Arabic World"
<?php
    require_once('url_to_absolute.php');
    $url = 'http://site.com/news/view.aspx?id=23032012';
    echo url_to_absolute($url, '/uploadedimages/Sections/Politics/Arabic World/original/Administrative-detention.jpg'), "
";
?>

it will not work and if there is arabic chars too

  • 写回答

1条回答 默认 最新

  • douzhuan4406 2012-03-24 08:09
    关注

    Code :

    <?php
    function code2utf($num){
      if($num<128) 
        return chr($num);
      if($num<1024) 
        return chr(($num>>6)+192).chr(($num&63)+128);
      if($num<32768) 
        return chr(($num>>12)+224).chr((($num>>6)&63)+128)
              .chr(($num&63)+128);
      if($num<2097152) 
        return chr(($num>>18)+240).chr((($num>>12)&63)+128)
              .chr((($num>>6)&63)+128).chr(($num&63)+128);
      return '';
    }
    
    function unescape($strIn, $iconv_to = 'UTF-8') {
      $strOut = '';
      $iPos = 0;
      $len = strlen ($strIn);
      while ($iPos < $len) {
        $charAt = substr ($strIn, $iPos, 1);
        if ($charAt == '%') {
          $iPos++;
          $charAt = substr ($strIn, $iPos, 1);
          if ($charAt == 'u') {
            // Unicode character
            $iPos++;
            $unicodeHexVal = substr ($strIn, $iPos, 4);
            $unicode = hexdec ($unicodeHexVal);
            $strOut .= code2utf($unicode);
            $iPos += 4;
          }
          else {
            // Escaped ascii character
            $hexVal = substr ($strIn, $iPos, 2);
            if (hexdec($hexVal) > 127) {
              // Convert to Unicode 
              $strOut .= code2utf(hexdec ($hexVal));
            }
            else {
              $strOut .= chr (hexdec ($hexVal));
            }
            $iPos += 2;
          }
        }
        else {
          $strOut .= $charAt;
          $iPos++;
        }
      }
      if ($iconv_to != "UTF-8") {
        $strOut = iconv("UTF-8", $iconv_to, $strOut);
      }   
      return $strOut;
    }
    ?>
    

    Try :

    <?php
       $newUrl = unescape($url);
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路