我之情況是:問題與PHP數組
用戶要檢查特定的(客戶)URL出現在目標網址或不和我創建簡單的腳本來測試特定的URL在一個目標網址。
這裏是我的PHP腳本:
if(isset($_POST['check_url']))
{
$client_url = $_POST['client_url'];
$destination_url = $_POST['destination_url'];
$contents = file_get_contents($destination_url);
$search = $client_url;
if(strpos($contents,$search)== FALSE)
{
echo "Not Found";
}
else
{
echo "Found";
}
}
這裏是我的HTML腳本:
<form method="post" action="test.php">
<label>Client URL:</label>
<input type="text" value="" name="client_url" /><br />
<label>Destination URL:</label>
<textarea value="" name="destination_url" ></textarea><br />
<button type="submit" name="check_url">Check</button>
</form>
上述腳本是工作在單目標網址的情況下,但是當我嘗試發佈多個目標網址(通過將其轉換爲陣列)我得到錯誤:
Warning: file_get_contents(http://learntk12.org/story.php?title=seo-link-building-service) [function.file-get-contents]: failed to open stream: No such file or directory in "path to source file" on line 24
其中第24行是:$contents[$i] = file_get_contents($arr[$i]);
這裏是我的PHP代碼數組:
if(isset($_POST['check_url']))
{
$client_url = $_POST['client_url'];
$destination_url = $_POST['destination_url'];
$destination =str_replace("\r",",",$destination_url);
$arr = explode(",",$destination);
$search = $client_url;
for($i=0;$i<count($arr);$i++)
{
$contents[$i] = file_get_contents($arr[$i]);
if (strpos($contents[$i], $search) === FALSE)
{
echo "Not Found";
}
else
{
echo "Found";
}
}
}
我在哪裏,在該腳本落後?
第一codelisting擁有無可匹敵的收盤'}' – Ikke
謝謝,我只是糾正了 – Arish