2014-01-24 63 views
0

我正在研究PHP/Ajax functions at W3schools.com。該源代碼對我來說很棒。但該代碼沒有超鏈接功能。所以我想從URL中的q參數創建一個超鏈接。如何修改gethint的PHP代碼?

所以我爲此做了PHP代碼。但我很長一段時間都處於虧損狀態。 以下是我的PHP代碼。

// Get the q parameter from URL 
$q = $_REQUEST["q"]; 
$hint = ""; 

// Lookup all hints from array if $q is different from "" 
if ($q !== "") 
{ 
    $q = strtolower($q); 
    $len = strlen($q); 
    foreach($a as $name) 
    { 
     if (stristr($q, substr($name, 0, $len))) 
     { 
      if ($hint === "") 
      { 
       $hint = $name; 
       echo '<a href="http://www.naver.com/"'$hint">" $hint"</a>"; 
      } 
      else 
      { 
       $hint .= ", echo '<a href="http://www.naver.com/"'$hint">" $hint"</a>"; 
      } 
     } 
    } 
} 

// Output "no suggestion" if no hint were found 
// or output the correct values 
echo $hint==="" ? "no suggestion" : $hint; 
?> 

我怎樣才能使A HREF =「HTTP:// WWW ...超級鏈接$提示或$名稱

+1

不要使用w3schools,請看這個鏈接更多http://www.w3fools.com/ –

回答

0

使用該打印網址:

echo '< a href="http://www.naver.com/"'.$hint.">".$hint."< /a>"; 
$hint='< a href="http://www.naver.com/"'.$hint.">".$hint."< /a>"; 
+0

真的,我很欣賞你的實物編碼。 – user3183995

+0

謝謝user3183995 –