次のセグメンテーション違反が発生するのはなぜですか。また、どうすればそれを防ぐことができますか?
<?php
$str = ' <fieldset> <label for="go-to">Go to: </label> '
. str_repeat(' ', 10000)
. '<input type="submit" value="Go" /> </fieldset> </form>';
preg_match_all("@
</?(?![bisa]\b)(?!em\b)[^>]*> # starting tag, must not be one of several inline tags
(?:[^<]|</?(?:(?:[bisau]|em|strong|sup)\b)[^>]*>)* #allow text and some inline tags
[\?\!\.]+
@ix", $str, $matches);
?>
私はそれが....それを待つ....スタックオーバーフローを引き起こしていると信じています。
編集:
上記は、問題を示すパターンの簡略版です。より完全なバージョン:
@
</?(?![bisa]\b)(?!em\b)[^>]*> # starting tag, must not be one of several inline tags
(?:[^<]|</?(?:(?:[bisau]|em|strong|sup)\b)[^>]*>)* # continue, allow text content and some inline tags
# normal sentence ending
[\?\!\.]+ # valid ending characters -- note elipses allowed
(?<!\b[ap]m\.)(?<!\b[ap]\.m\.)(?<!digg this\!)(?<!Stumble This\!) # disallow some false positives that we don't care about
\s*
(?:'|&\#0*34;|'|‘)?\s* # closing single quotes, in the unusual case like "he said: 'go away'".
(?:"|"|&\#0*34;|&\#x0*22;|”|&\#0*8221;|&\#x0*201D;|''|``|\xe2\x80\x9d|&\#0*148;|&\#x0*94;|\x94|\))?\s* # followed by any kind of close-quote char
(?=\<) # should be followed by a tag.
@ix
目的は、有効な英語の文の終わりのように見えるもので終わるように見えるhtmlブロックを見つけることです。この方法は、「コンテンツ」テキスト(記事の本文など)と「レイアウト」テキスト(ナビゲーション要素など)の違いを区別するのに非常に優れていることがわかりました。ただし、タグの間に大量の空白があると、爆発することがあります。