2014-12-28 2 views
-5

이 내 코드를 확인하십시오.PHP는 간단한 HTML DOM은 variabile

어떻게이 변수를 foreach 내부에서 작동하도록 만들 수 없습니까? 나는 내 데이터베이스

+0

가능한 중복 (http://stackoverflow.com/questions/27677099/php-simple 같이해야한다 -html-dom-img-custom-data) – AeroX

+0

이 웹 사이트에서 디버깅 요청을 게시하지 마십시오. 웹 사이트는 프로그래밍 관련 질문을위한 것입니다. 실제 코드를 잘라내어 붙여 넣는 대신 처음부터 문제를 설명하는 데 필요한 코드를 사용하여 예제를 작성하십시오. 단, 지금까지 해당 주제에 대한 기존 답변을 찾을 수없는 경우에만 가능합니다. – hakre

답변

0

의 변수를 가져올 당신은 배열

require_once 'simple_html_dom.php'; 
    $html = new simple_html_dom(); 
    $html->load_file('http://www.example.com/?search=movies'); 

    $videos=array(); 
    $ret = $html->find('span.video-title'); 
    $counter=0; 
    foreach($ret as $elements) { 
    foreach($elements->find('a') as $link) { 
     $id = $link->href; 
     $videos[$counter]['ID']=$id; 
     $counter++; 
    } 
    } 


$counter=0; 

    foreach($html->find('span.video-title') as $titlu) { 
    $title = $titlu->find('a', 0)->innertext; 
    $videos[$counter]['title']=$title; 
    $counter++; 
    } 

    $counter=0; 
    foreach($html->find('span.video-duration') as $durata) { 

    $time = $durata->outertext; 
$videos[$counter]['time']=$time; 
    $counter++; 
    } 

    $counter=0; 
    foreach($html->find('img.lazy') as $imagine) { 
    $images = $imagine->getAttribute('data-src'); 
$videos[$counter]['images']=$images; 
    $counter++; 

    } 


    echo $id; 
    echo $title; 
    echo $time; 
    echo $images; 
+0

구문 분석 오류 : 구문 오류, 38 번째 줄에있는 C : \ xampp \ htdocs \ file.php의 예기치 않은 '$ counter'(T_VARIABLE)이 마지막 $ counter ++입니다. – user3356954

+0

가 추가되었습니다. 이제 semiclon이 누락되었습니다. – cirtrus

+0

이 코드는 약간의 품질을 제공합니다. @citrus 옆에 이름을 올리는 것을 거부하지 않았습니까? – hakre

0

당신은 각 문자열 (HTML)를 연결할한다의 비디오 데이터를 저장해야합니다. 당신은 모든 결과를 얻을 수 있도록 ... 코드는 [PHP는 간단한 HTML DOM img와 사용자 정의 데이터]의

require_once 'simple_html_dom.php'; 
$html = new simple_html_dom(); 
$html->load_file('http://www.example.com/?search=movies'); 

$id = ""; 
$title = ""; 
$images = ""; 
$time = ""; 
$ret = $html->find('span.video-title'); 

foreach($ret as $elements) { 
foreach($elements->find('a') as $link) { 
    $id .= $link->href; 
} 
} 


foreach($html->find('span.video-title') as $titlu) { 
$title .= $titlu->find('a', 0)->innertext; 

} 


foreach($html->find('span.video-duration') as $durata) { 

$time. = $durata->outertext; 
} 

foreach($html->find('img.lazy') as $imagine) { 
$images .= $imagine->getAttribute('data-src'); 

} 


echo $id; 
echo $title; 
echo $time; 
echo $images;