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.
文字列から次のパターンを削除しようとしています:
<div class="main_title">Content 1</div>
ここで、'Content 1' は文字列によって異なる場合があります。
以下は機能していないようです。
$output = preg_replace('<div class="main_title">.*</div>', " ", $output);
明らかな何かが欠けていますか?
コメントで他の人が言っているように、HTML を解析するために正規表現を使用しないでください。代わりに SimpleXML または DOMDocument を使用してください。まだ正規表現が必要な場合は、パターン区切り文字をコードに入れる必要があります。
$output = preg_replace('#<div class="main_title">.*</div>#', " ", $output);