▽1
●
a-kuma3 ●300ポイント ベストアンサー |
2番目の <H3> の前に bbb と入れるだけであれば、こんな感じで。
<?php function before_h3($the_content) { $moji = 'aaa'; $h3 = '/(<h3.*?>.*?)(<h3)/i'; $the_content = preg_replace($h3, '$1' . $moji . '$2', $the_content, 1); return $the_content; }
質問にある 1番目の前に aaa を入れるのも合わせてやるなら、こんな感じです。
<?php function before_h3($the_content) { $moji_a = 'aaa'; $moji_b = 'bbb'; $h3 = '/(<h3.*?>.*?)(<h3)/i'; $the_content = preg_replace($h3, $moji_a . '$1' . $moji_b . '$2', $the_content, 1); return $the_content; }