簡體   English   中英

pathinfo()在本地主機上運行,​​但不在實時服務器上運行

[英]pathinfo() working on localhost but not on the live server

$name = pathinfo($num)['filename']; this is line 15.

錯誤:

[25-Sep-2013 05:32:00] PHP解析錯誤:語法錯誤,/xxxx/xxxxxxxxx/xxxxx/xxxxxxx/xxxxxxxx/Project/mainpage.php在第15行出現意外的[[]。

相同的代碼可以在XAMP的localhost上完美運行!

還有其他我應該嘗試的方法嗎?

您在服務器上擁有哪個PHP版本? 可能小於5.4。 在本地主機上,您可能擁有5.4。

那就是問題所在。 類似pathinfo($num)['filename']類的語法僅在PHP 5.4中有效。

要么在服務器上升級PHP,要么按照Amol的建議進行操作。

因為pathinfo($num)不是數組,所以可能發生此錯誤。 請更新為:

<?php
$pInfo = pathinfo($num);
$name = '';
if (! empty($pInfo) && is_array($pInfo)) {
  $name = $pInfo['filename']; //this is line 15.
}
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM