Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
文字列に対して PHP 関数を実行したいのですが、preg_replaceアンカー タグ内のものを無視する必要があります。
preg_replace
例えば。
string = 'alpha beta delta gamma <a href="somelink.html">alpha beta delta gamma</a>' to match = 'beta delta'
2番目のインスタンスではなく、最初のインスタンスのみをピックアップするにはどうすればよいbeta deltaですか?
beta delta
終了タグの否定先読みを行うことができます:
preg_replace("/$to_match(?![^<]*<\/)/", 'foo', $string);
また、html で正規表現を使用しないでください。