2013-09-06 2 views
0

domdocument에 관한 질문이 있습니다.PHP domdocument 조작 문제

$html는 내 html로 변수가 테이블 요소가있는 경우 감지 할

texts …paragraph.. 

<table class='test'> 
    tr and td... 
</table> 

texts and more texts 

같은 것을 포함한다. 그렇다면 <p> 태그에 다른 텍스트를 포함하십시오.

그래서 누군가가 이것에 대해 저를 도와 줄 수

<p>texts …paragraph..</p> 

<table class='test'> 
    tr and td... 
</table> 

<p>texts and more texts</p> 

내 코드는

$doc = new DOMDocument(); 
$doc->loadHTML($htmlString); 

$tables = $doc->getElementsByTagName('table'); 

    foreach ($tables as $table) { 
     //I am not sure what to do next... 
    } 

처럼되는 것인가? 정말 고마워!

답변

-1

나는 이것을 테스트하지 못했습니다.

$html = preg_replace('/(<table.*</table>)/i','<p>$1</p>', $html); 

... 희망이 도움이