当我通过链接到我的函数时出现错误require()
错误:Parse error: syntax error, unexpected T_PUBLIC, expecting T_STRING in /home/content/23/9953123/html/new/lib/functions.php on line 3
代码:
<?php
require("lib/functions.php");
require("lib/dbconnect.php");
?>
函数.php:
<?php
function stateToAbb($input){
//reset found
$found = 0;
//list states
$states = "Alaska,Alabama,Arkansas,Arizona,California,Colorado,Connecticut,Delaware,Florida,Georgia,Hawaii,Iowa,Idaho,Illinois,Indiana,Kansas,Kentucky,Louisiana,Massachusetts,Maryland,Maine,Michigan,Minnesota,Missouri,Mississippi,Montana,North Carolina,North Dakota,Nebraska,New Hampshire,New Jersey,New Mexico,Nevada,New York,Ohio,Oklahoma,Oregon,Pennsylvania,Rhode Island,South Carolina,South Dakota,Tennessee,Texas,Utah,Virginia,Vermont,Washington,Wisconsin,West Virginia,Wyoming";
//list abbreviations
$abb = "AK,AL,AR,AZ,CA,CO,CT,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VA,VT,WA,WI,WV,WY";
//create arrays
$states_array = explode(",", $states);
$abb_array = explode(",", $abb);
//run test
for ($i = 0; $i < count($states_array); $i++){
if (strtolower($input) == strtolower($states_array[$i])){
$found = 1;
$output = $abb_array[$i];
return $output;
}
}
if ($found != 1){
$output = $input;
return $output;
}
return $output;
}
?>
但是当我只是将函数放入文件中而不需要单独的 php 文件时,它工作得很好......
有任何想法吗?
更新...
由于每个人都认为我试图拉一个快速的并使用不同的代码......这是一个更新的代码......
<?php
require("lib/functions.php");
require("lib/dbconnect.php");
function stateToAbb($input) {
//reset found
$found = 0;
//list states
$states = "Alaska,Alabama,Arkansas,Arizona,California,Colorado,Connecticut,Delaware,Florida,Georgia,Hawaii,Iowa,Idaho,Illinois,Indiana,Kansas,Kentucky,Louisiana,Massachusetts,Maryland,Maine,Michigan,Minnesota,Missouri,Mississippi,Montana,North Carolina,North Dakota,Nebraska,New Hampshire,New Jersey,New Mexico,Nevada,New York,Ohio,Oklahoma,Oregon,Pennsylvania,Rhode Island,South Carolina,South Dakota,Tennessee,Texas,Utah,Virginia,Vermont,Washington,Wisconsin,West Virginia,Wyoming";
//list abbreviations
$abb = "AK,AL,AR,AZ,CA,CO,CT,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VA,VT,WA,WI,WV,WY";
//create arrays
$states_array = explode(",", $states);
$abb_array = explode(",", $abb);
//run test
for ($i = 0; $i < count($states_array); $i++){
if (strtolower($input) == strtolower($states_array[$i])){
$found = 1;
$output = $abb_array[$i];
return $output;
}
}
if ($found != 1){
$output = $input;
return $output;
}
return $output;
}
?>
它不起作用...当我删除require("lib/functions.php");
它时它起作用了,所以问题在于那行代码