LoginSignup
0
0

【PHP】html要素から<h2>のみを削除する 正規表現で置換を行う preg_replaceを使う

Last updated at Posted at 2023-05-09

コード

<?php
$contents = '<h1>aaa</h1><h2 class="">bbb</h2><h3>ccc</h3>';
echo preg_replace('/<h2.*>(.*?)<\/h2>/','', $contents);

結果

<h1>aaa</h1><h3>ccc</h3>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0