我得到一個錯誤,當我通過require()
T_PUBLIC,期待T_STRING使用要求()
錯誤鏈接到我的功能: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");
?>
的functions.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文件,它的工作原理很好...
任何想法?
UPDATE ...
因爲每個人都認爲我試圖瞞過和使用不同的代碼...... 這裏是一個更新的代碼...
<?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");
它的工作原理是這樣的問題是與該行代碼
1. SO不是您的個人解析器2.我相信您會向我們展示不同的文件 – Peter
顯示的代碼沒有問題,請嘗試發佈其他文件。 – Supericy
我只是猜測:你有一個'public function foobar(){/ * code * /}'在類的某個地方。這是不可能的,不允許和除此之外,它甚至沒有多大意義:D – KingCrunch