2013-08-16 2 views
0

URL이 5000 라인 인 txt 파일이 있습니다. 내가하려는 일은 모든 URL을 열어 모든 URL (첫 번째 URL에 있음)을 추출하는 것입니다. 제 문제는 스크립트가 URL을 열고 문제가없는 링크가 몇 개인 지 알려주는 첫 번째 줄입니다. 하지만 ... 이런 식으로 배열 쇼 뭔가 아무것도 보여 밤은의 URL의 파일의 나머지 :URL 및 구문 분석 정보 읽기

Array 
(
) 
Array 
(
) 

내 코드 :

$homepage = file_get_contents('***mytxt file****'); 

$pathComponents = explode(",", trim($homepage)); //line breaker 

//echo "<pre>";print_r($pathComponents);echo "</pre>"; 

$count_nlines = count($pathComponents); 

for ($i=0;$i<3;$i++) { 

$request_url = $pathComponents[$i]; 
//echo $request_url . "<br>"; 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $request_url); // The url to get links from 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // We want to get the respone 
$result = curl_exec($ch); 

$regex='|<a.*?href="(.*?)"|'; 
preg_match_all($regex,$result,$parts); 
$links=$parts[1]; 

echo "<pre>";print_r($links);echo "</pre>"; 

curl_close($ch); 
} 

어떤 아이디어가?!

+0

당신이 당신의 배열 파일의 예를 가지고 있습니까 : 여기에

for ($i=0;$i<3;$i++) { 

이를 변경해보십시오? –

+0

내가받은 첫 번째 배열을 의미합니까? – subversive

+0

.txt 파일에 배열이 없습니다. –

답변

0

잘못된 것을 반복하고있는 것처럼 보입니다.

for ($i = 0; $i <= count($pathComponents); $i++) 
+0

동일합니다 : S – subversive

+0

@subversive 죄송합니다.이 컴퓨터 (내 작업 컴퓨터)에 PHP가 없으므로 코드를 테스트 할 수 없습니다. 나는 직장에서 C#을한다. (PHP는 내 집 컴퓨터에있다.) 바라건대, 프레드는 당신에게 몇 가지 코드를 줄 수있을 것입니다. 그렇지 않은 경우 여기에 수행하려는 작업을 수행하는 또 다른 옵션이 있습니다. http://stackoverflow.com/questions/7031058/using-curl-to-get-all-links-in-a-website-not-only-the -page 및 http://www.jaygilford.com/php/common-questions/how-to-get-all-links-from-a-web-page/ 및 http://www.qualitycodes.com/tip/ 27/using-curl-to-all-links-in-a-webpage.html – user1477388