2013-01-02 4 views
1

내 시나리오에는입니다 . 여기 문제는

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 스크립트입니다 : 여기

내 PHP 스크립트입니다 위의 스크립트는 하나의 대상 URL의 경우 작동되지만

<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> 

여러 개의 대상 URL을 게시하려고 할 때 (배열로 변환하여) 오류가 발생했습니다 :

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 행은 :입니다.

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"; 
     } 
    } 


} 

나는이 스크립트에 떨어지고 오전 : 여기

배열 내 PHP 코드?

+0

첫 번째 codelisting은 타의 추종을 불허하는 폐쇄가'}' – Ikke

+0

덕분에 난 그냥 – Arish

답변

1

이 시도 :

if (isset($_POST['check_url'])) 
{ 
    $client_url = $_POST['client_url']; 
    $destination_url = $_POST['destination_url']; 
    $destinations = str_replace(array("\r\n", "\n"), ',', $destination_url); // replace both types of line breaks with a comma, \r alone will not suffice 
    $destinations = explode(',', $destinations); // split at commas 

    foreach ($destinations as $destination) // loop through each item in array 
    { 
     $contents = file_get_contents($destination); // get contents of URL 

     echo (FALSE === strpos($contents, $client_url)) // check if remote data contains URL 
      ? 'Not Found' // echo if TRUE of above expression 
      : 'Found'; // echo if FALSE of above expression 
    } 
} 
+0

감사 수수께끼 같은 오류 메시지를 받았습니다 – Arish

+1

@Arish, 예, 잠깐 내 코드에 주석을 달아주세요. –

0

멀리까지 나는 당신에게 배열 $ 내용이 없다는 것을 본다. 그것은 다음과 같이 작동합니다 :

$contents = file_get_contents($arr[$i]); 
if (strpos($contents, $search) === FALSE) { 
    echo "Not Found"; 
} else { 
    echo "Found"; 
} 
+0

것을 수정, 그것을 가지고 . 이 스크립트의 작동 방식을 제발 설명해 주시겠습니까 – Arish