如何修改gethint的PHP代码?

时间:2014-01-24 14:28:35

标签: javascript php ajax

我正在研究PHP/Ajax functions at W3schools.com。那个源代码对我来说太神奇了。但该代码没有超链接功能。所以我想从URL中的q参数创建一个超链接。

所以我为此目的制作了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;
?>

如何制作href =“http:// www ...超链接$ hint或$ name?

1 个答案:

答案 0 :(得分:0)

用它来打印网址:

echo '< a href="http://www.naver.com/"'.$hint.">".$hint."< /a>"; 
$hint='< a href="http://www.naver.com/"'.$hint.">".$hint."< /a>";
相关问题