2016-08-30 3 views
0

나는 다음과 같은 코드를 분석하려고 해요 : 내가 필요한 기본적구문 분석 HTML 요소는

<table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%" id="bodyTable" style="table-layout: fixed;max-width:100% !important;width: 100% !important;min-width: 100% !important;"> 

입니다 : 간단한 explode(" ", $str);와 함께이 일을 할 때 내가 갖는 그러나

Array 
(
    [0] => <table 
    [1] => border="0" 
    [2] => cellpadding="0" 
    [3] => cellspacing="0" 
    [4] => height="100%" 
    [5] => width="100%" 
    [6] => id="bodyTable" 
    [7] => style="table-layout: fixed;max-width:100% !important;width: 100% !important;min-width: 100% !important; 
) 

"스타일"도 나뉘어져 있습니다.이 구문을 분석하고이를 반복하는 간단한 방법이 있습니까?

+0

이'style' 속성 내부에서 공백을 제거합니다. – coderodour

+0

빠른 해킹 솔루션을 찾고 있다면 정규식을 사용해 볼 수도 있습니다. – dan08

+0

http://php.net/manual/en/function.explode.php – Aaron

답변

0

이 시도 : 당신이 폭발`에 구분 기호()`으로 공간을 사용하는 경우

$result = array(); 
$str = '<table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%" id="bodyTable" style="table-layout: fixed;max-width:100% !important;width: 100% !important;min-width: 100% !important;">'; 
$str_arr = explode (' style', $str); 
$result = explode (' ', $str_arr[0]); 
array_push($result, 'style'.$str_arr [1]); 

echo '<pre>'; 
print_r($result);