난 당신이를 위해 정규 표현식을 사용할 수있는 것 같아요 :
echo preg_replace_callback('/\s([\w]{1,}=)((?!")[\w]{1,}(?!"))/', function($matches){
return ' '.$matches[1].'"'.$matches[2].'"';
}, $str);
그리고 초래 :
<td width="140" style='width:105.0pt;padding:0cm 0cm 0cm 0cm'>
<p class="MsoNormal"><span style='font-size:9.0pt;font-family:"Arial","sans-serif";
mso-fareast-font-family:"Times New Roman";color:#666666'>OCCUPANCY
TAX:</span></p>
</td>
Eval.in live example
이 같은 것을 구현 될 것
/\s([\w]{1,}=)((?!")[\w]{1,}(?!"))/g
\s match any white space character [\r\n\t\f ]
1st Capturing group ([\w]{1,}=)
[\w]{1,} match a single character present in the list below
Quantifier: {1,} Between 1 and unlimited times, as many times as possible, giving back as needed [greedy]
\w match any word character [a-zA-Z0-9_]
= matches the character = literally
2nd Capturing group ((?!")[\w]{1,}(?!"))
(?!") Negative Lookahead - Assert that it is impossible to match the regex below
" matches the characters " literally
[\w]{1,} match a single character present in the list below
Quantifier: {1,} Between 1 and unlimited times, as many times as possible, giving back as needed [greedy]
\w match any word character [a-zA-Z0-9_]
(?!") Negative Lookahead - Assert that it is impossible to match the regex below
" matches the characters " literally
g modifier: global. All matches (don't return on first match)
참고로, 이것은 더럽고 더러운 예제이며 확실하게 정리할 수 있습니다.
네이티브 PHP 함수가 없으며 이미 새 니타 이징되었습니다. ''''정말로 ** 필수적인 ** 시간은 오직 값에 특수 문자 나 공백이있을 때입니다. 그 점을 감안할 때, 나는 승화와 같은 텍스트 편집기를 사용하여 파일을 직접 정리하는 것이 가장 좋을 것이라고 생각합니다. – Ohgodwhy
이 프로그래밍 방식으로 해결해야합니다. quoted_printable_decode() 함수를 사용하고 있기 때문에 너비가 140 = 따옴표가없는 140은 나에게 문제가된다. 그러나 함께 = '140'(따옴표 포함) 괜찮습니다. 하지만 전체 파일에서 모든 attributtes를 인용하는 영리한 방법을 원합니다. –
[PHP DOM 파서] (http://simplehtmldom.sourceforge.net/)일까요? –