0
DOM 파서를 사용하여 요소의 N 번째 인스턴스를 가져 오려고합니다.이 경우 첫 번째 DIV CLASS 요소는 에코 만 사용합니다. 오류가 발생합니다. Notice : "Array to string conversion". implode 함수를 사용하여 결합하여 문자열로 만들려고 시도했지만 아무 것도 작동하지 않는 것 같습니다. 내가 도대체 뭘 잘못하고있는 겁니까? 여기에 함수가 있지만 http://code.tutsplus.com/tutorials/html-parsing-and-screen-scraping-with-the-simple-html-dom-library--net-11856하지만 같은 결과를 얻을 수 없습니다.문자열 변환 DOM 파서에 배열
function my_function($str) {
require_once 'libs/simple_html_dom.php';
$html = file_get_html($str);
foreach($html->find('div[class=copy]', 0) as $element){
$patterns = array();
$patterns[0] = 'some';
$patterns[1] = 'cool';
$replacements = array();
$replacements[0] = 'really';
$replacements[1] = 'super';
$replacements[3] = ' ';ksort($patterns);ksort($replacements);
echo str_replace($patterns, $replacements, $element);
}
}
문제 어딘가에 여기
foreach($html->find('div[class=copy]', 0) as $element)
난 단지 1 인스턴스를 캡처하고 그것을 반향하기 위해 노력하고있어
<div class="copy">somecooltext1</div>
<div class="copy">somecooltext2</div>
<div class="copy">somecooltext3</div>
<div class="copy">somecooltext4</div>
<div class="copy">somecooltext5</div>
마크 업.
에 당신이'위해서 var_dump ($ 요소) 봤어
을 변경 그것을 밖으로 생각? – Barmar
'$ html-> find ('div [class = copy]', 0)'를 인쇄 해보십시오. 여기에 글을 올리십시오. –