我试图从另一个网站获取内容。以下是php代码。但是当我运行它时,它会显示错误消息。
错误讯息:
Parse error: syntax error, unexpected '–' (T_STRING) in D:\Software\Installed\xampp\htdocs
\test\index.php on line 10
Php代码:
<?php
function get_string_between($string, $start, $end)
{
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0)
return "";
$ini += strlen($start);
$len = strpos($string, $end, $ini) – $ini; // this is line number 10.
return substr($string,$ini,$len);
}
//Initialize the Curl session
$ch = curl_init();
//Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//Set the URL
curl_setopt($ch, CURLOPT_URL,"http://www.test.org/");
//Execute the fetch
$data = curl_exec($ch);
echo $da=get_string_between($data,'imgs/topdown.gif">','imgs/topdown.gif');
//Close the connection
curl_close($ch);
?>
答案 0 :(得分:2)
第10行中的-
不是正常减号。这是另一个ASCII字符,这就是弄乱它。
尝试用减号替换该字符。