0

私はこれで遊んでいて、これが残っています...

preg_match_all('/<p>(.*?)<br>(.*?)<p>/s', $offices, $district);

これは正常に機能しています...しかし、もちろん、問題を引き起こしているレコードが1つあります。<p>タグ内のすべてのテキストを指定して取得するにはどうすればよい<br>ですか? <br>できれば、Eddy Lite タグ内で複数指定し<p>、タグを除外しますか?

文字列は次のようなアドレスです。

    <h3>District Offices:</h3>
<p>
317 Dun Avenue<br>Suite 17<br>Port Samson, AK 32675<br>
(XXX) XXX-XXXX<br> 
VOIP: 40800<br> 
FAX (888) xxx-38xx<br> 

</p>

<h4>Staff Assistants:</h4>
<p>Beth Booger and Ly Sweet</p>

<h4>Secretary:</h4>
<p>Eddy Lite </p>

<p>
OK City Hall<br>110 S.E. Five Avenue<br>3rd Floor<br>Corpse, AK 33371<br>
(xxx) 694-xxxx<br> 

</p>

<h4>Staff Assistant:</h4>
<p>Con Sims </p>

    <br />

<h3>Home Office:</h3>

これは私が得ているものです: Array ( [0] => Array ( [0] => 317 Dun Avenue Suite 17 Port Samson, AK 32675 (XXX) XXX-XXXX

Staff Assistants:

[1] =>

Eddy Lite 

OK City Hall
110 S.E. Five Avenue
3rd Floor
Corpse, AK 33371
(xxx) 694-xxxx
Staff Assistant:

) )

どんな助けでも大歓迎です。私は試しました: preg_match_all('/

(.*?)

/s', $offices, $district); preg_match_all('/

(.*)

/s', $offices, $district); preg_match_all('/

(. ?)
(.
?)

/', $offices, $district); preg_match_all('/

(. ?)
(.
?)
(.*?)

/s', $offices, $district); preg_match_all('/

(. ?)
(.
)
(.*)

/s', $offices, $district);

4

2 に答える 2

0

これを試して

'~<p>(?=((?!</p>).)*<br>)((?!Eddy Lite).)*?</p>~s'
于 2013-01-20T17:36:52.667 に答える
0

簡単な回避策は、プレーン テキストと<br>タグのみを許可することです。

preg_match_all('#<p>([^<>]*<br\s*/?>[^<>]*)+</p>#s', $offices, $district);

通常の注意: このような正規表現は、一貫性のある既知の入力に対してのみ機能します。

于 2013-01-20T17:37:05.707 に答える