坏网址解码和URIerror

时间:2014-03-17 21:12:37

标签: php

我用错误的网址代码遇到了问题。

例如:

Alléedescassis ”应为“所有%C3%A9e%20des%20cassis%0A

但是我的代码产生了“所有%E9e%20des%20cassis

然后decodeURIComponent javascript函数产生一个URIerror: - (

可能有办法解决这个问题。

由于

我使用此代码livesearch.php

<?php
$xmlDoc=new DOMDocument();
$xmlDoc->load("livesearch.xml");

$x=$xmlDoc->getElementsByTagName('link');

//get the q parameter from URL
$q=$_GET["q"];

//lookup all links from the xml file if length of q>0
if (strlen($q)>0)
{
$hint="";
for($i=0; $i<($x->length); $i++)
  {
  $y=$x->item($i)->getElementsByTagName('title');
  $z=$x->item($i)->getElementsByTagName('url');
  $massif=$x->item($i)->getElementsByTagName('title');//var massif

  if ($y->item(0)->nodeType==1)
    {
    //find a link matching the search text
    if (stristr($y->item(0)->childNodes->item(0)->nodeValue,$q))
      {
      if ($hint=="")
        {
        $hint="<a href='" . 
        $z->item(0)->childNodes->item(0)->nodeValue . 
        "' target='_blank'>" . 
        $y->item(0)->childNodes->item(0)->nodeValue . "</a>";       

        }
      else
        {
        $hint=$hint . "<br /><a href='" . 
        $z->item(0)->childNodes->item(0)->nodeValue . 
        "' target='_blank'>" . 
        $y->item(0)->childNodes->item(0)->nodeValue . "</a>";
        }
      }
    }
  }
}

// Set output to "no suggestion" if no hint were found
// or to the correct values
if ($hint=="")
  {
  $response="Oups! Aucune suggestion.";
  }
else
  {
  $response=$hint;
  }

//output the response
echo $response;

?>

和xml文件

<?xml version="1.0" encoding="UTF-8"?>
<pages>

  <link>
    <title>95.2</title>
    <url>blocableau3x.html?95.2</url>
  </link>
....
....
  <link>
    <title>Allée des cassis</title>
    <url>blocableau3x.html?Allée des cassis</url>
  </link>
  <link>
    <title>Apremont</title>
    <url>blocableau3x.html?Apremont</url>
  </link>
</pages>

0 个答案:

没有答案