你的代碼改成這樣,看看它是如何去
<script>
function doSomething()
{
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function()
{
if (xhttp.readyState == 4)
{
if (xhttp.status == 200)
document.getElementById("calContent").innerHTML = xhttp.responseText;
}
}
xhttp.open("GET", "/num/ns.php?number=" + jQuery("#nInput").val() + "$$$" + jQuery('input[name=switcher]:checked').val(), true);
xhttp.send();
}
function doSomethingElse()
{
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function()
{
if (xhttp.readyState == 4)
{
if (xhttp.status == 200)
document.getElementById("calContent").innerHTML = xhttp.responseText;
}
}
xhttp.open("GET", "/num/ns.php?number2=" + jQuery("#nInput2").val() + "$$$" + jQuery('input[name=switcher2]:checked').val(), true);
xhttp.send();
}
</script>
<style>
.calOut {
position: relative;
float: left;
margin-right: 18px;
}
</style>
<style media="print">
#calContent { display: none; }
</style>
<div id="calContent" style="margin-top: 0px; margin-bottom: 50px; color:black;" class="contact_form" >
<?php
$numname = "number";
if (isset($_GET["number"])) {
echo "<div><input type='text' id='nInput' name='nInput' value='" . explode("$$$", $_GET["number"])[0] . "' />";
echo "<br /><input type='radio' name='switcher' value='female' "; if (explode("$$$", $_GET["number"])[1] == "female") echo "checked"; echo ">Female ";
echo "<input type='radio' name='switcher' value='male' " . (explode("$$$", $_GET["number"])[1] == "male" ? "checked" : "") . ">Male ";
echo "<input type='radio' name='switcher' value='last' " . (explode("$$$", $_GET["number"])[1] == "last" ? "checked" : "") . ">Last name ";
}
else {
echo "<div><input placeholder='Enter vibration' type='text' id='nInput' name='nInput' />";
echo "<br /><input type='radio' name='switcher' value='female' checked>Female <input type='radio' name='switcher' value='male' >Male ";
echo "<input type='radio' name='switcher' value='last' />Last name";
}
echo "<br /><input type='submit' id='nForm' value='Generate names' onclick='doSomething()' class='qbutton' style='margin-bottom: 45px;'/><br /></div>";
if (isset($_GET["number2"])) {
echo "<div><input type='text' id='nInput2' name='nInput2' value='" . explode("$$$", $_GET["number2"])[0] . "' />";
echo "<br /><input type='radio' name='switcher2' value='female' "; if (explode("$$$", $_GET["number2"])[1] == "female") echo "checked"; echo ">Female ";
echo "<input type='radio' name='switcher2' value='male' " . (explode("$$$", $_GET["number2"])[1] == "male" ? "checked" : "") . ">Male ";
echo "<input type='radio' name='switcher2' value='last' " . (explode("$$$", $_GET["number2"])[1] == "last" ? "checked" : "") . ">Last name ";
$numname = "number2";
}
else {
echo "<div><input placeholder='Enter vibration and number, eg. Lisa 17/8' type='text' id='nInput2' name='nInput' />";
echo "<br /><input type='radio' name='switcher2' value='female' checked>Female <input type='radio' name='switcher2' value='male' >Male ";
echo "<input type='radio' name='switcher2' value='last' />Last name";
}
echo "<br /><input type='submit' id='nForm2' value='Generate names' onclick='doSomethingElse()' class='qbutton' /><br /></div>";
//echo $_SERVER['HTTP_REFERER'];
//echo "<br />";
//if ($_SERVER['REMOTE_ADDR'] == "93.176.86.170" || $_SERVER['REMOTE_ADDR'] == "86.52.165.122")
// echo $_SERVER['REQUEST_URI'];
$values = [
"a" => 1, "i" => 1, "j" => 1, "q" => 1, "y" => 1, "å" => 1, "á" => 1, "à" => 1,
"b" => 2, "k" => 2, "r" => 2,
"c" => 3, "g" => 3, "l" => 3, "s" => 3, "ç" => 3,
"d" => 4, "m" => 4, "t" => 4,
"e" => 5, "h" => 5, "n" => 5, "x" => 5, "é" => 5, "è" => 5, "è" => "5",
"u" => 6, "v" => 6, "w" => 6, "æ" => 6,
"o" => 7, "z" => 7, "ø" => 7, "ô" => 7, "ó" => 7, "ò" => 7, "ö" => 7,
"f" => 8, "p" => 8];
?>
<br />
<?php
//ini_set('memory_limit', '2048M');
error_reporting(0);
ini_set("display_errors", 0);
ini_set("log_errors", 0);
ini_set("error_reporting", 0);
if (isset($_GET[$numname]))
{
$namecount = 0;
if (is_numeric(explode("/", explode("$$$", $_GET["number"])[0])[0]))
{
echo "<br />";
if (explode("$$$", $_GET[$numname])[1] == "male")
$handle = fopen("./malenames.txt", "r");
else if (explode("$$$", $_GET[$numname])[1] == "female")
$handle = fopen("./femalenames.txt", "r");
else
$handle = fopen("./surnames.txt", "r");
$output = Array();
if ($handle)
{
while (($line = fgets($handle)) !== false)
{
$bVal = 0;
for($j=0;$j<=strlen(utf8_decode($line));$j++)
{
$bVal += $values[substr(utf8_decode(mb_strtolower($line)),$j,1)];
}
if ($bVal==explode("/", explode("$$$", $_GET[$numname])[0])[0] || explode("/", explode("$$$", $_GET[$numname])[0])[0] == (1+(($bVal-1)%9)))
{
//echo $line . "<br />";
$output[$namecount] = $line . " (" . $bVal . "/" . (1+(($bVal-1)%9)) . ")<br />";
$namecount++;
}
//echo $line . "<br />";
}
fclose($handle);
echo "<p id='numcount'>Found " . $namecount . " names</p>";
echo "<br />";
for ($i=0;$i<count($output);$i++)
echo $output[$i];
unset($output);
}
}
else if (is_numeric(explode(" ", explode("/", explode("$$$", $_GET[$numname])[0])[0])[1]))
{
$parm1 = explode(" ", explode("$$$", $_GET[$numname])[0]);
$oldname = utf8_decode($parm1[0]);
$num = explode("/", $parm1[1])[0];
//echo "<p>" . $parm1 . "</p>";
//echo "<p>" . $oldname . "</p>";
//echo "<p>" . $num . "</p>";
echo "<br />";
if (explode("$$$", $_GET[$numname])[1] == "male")
$handle = fopen("./malenames.txt", "r");
else if (explode("$$$", $_GET[$numname])[1] == "female")
$handle = fopen("./femalenames.txt", "r");
else
$handle = fopen("./surnames.txt", "r");
$output = Array();
if ($handle)
{
while (($line = fgets($handle)) !== false)
{
$linex = $parm1[0] . mb_strtolower($line);//utf8_decode(mb_strtolower($oldname . mb_strtolower($line)));
$bVal = 0;
for($j=0;$j<=strlen(utf8_decode($linex));$j++)
{
$bVal += $values[substr(utf8_decode(mb_strtolower($linex)),$j,1)];
}
if ($bVal==$num || $num == (1+(($bVal-1)%9)))
{
//echo $line . "<br />";
$output[$namecount] = $linex . " (" . $bVal . "/" . (1+(($bVal-1)%9)) . ")<br />";
$namecount++;
}
//echo $line . "<br />";
}
fclose($handle);
echo "<p id='numcount'>Found " . $namecount . " names</p>";
echo "<br />";
for ($i=0;$i<count($output);$i++)
echo $output[$i];
unset($output);
}
}
else
{
echo "<br />Error in input";
}
echo "<div style='clear:both;'></div>";
}
?>
</div>
<script src="http://code.jquery.com/jquery-latest.min.js"
type="text/javascript"></script>
[PHP的可能重複: 「請注意:未定義的變量」, 「通知:未定義指數」 和「注意事項:Undefined offset「](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef) – miken32
@ miken32感謝您的回覆。儘管我很欣賞你花時間回答這個問題,但鏈接的文章並沒有解釋爲什麼它能在服務器上運行,而不是在我的本地環境中運行(至少不是我所能理解的),這是真正的問題。如果我錯了,請指出具體的報價。然而,再次感謝您的時間! – DCBN
可能有多種原因,但問題的根本在於'$ values [whatever]'不存在。首先我要檢查的是你已經安裝了多字節功能。同時檢查您嘗試用作索引的值。 – miken32