replace h1 tag with h2 tag
Posted: Sun Apr 17, 2016 1:38 pm
Hi everyone. I created an admin section where an admin user can modify aspects of the site (home page, about us, etc). This code retrieves 500 characters correctly, but I need to convert any h1-h6 to <h2>...</h2>.. Right now, the content is retrieved as it was saved in the db, and the h1-h6 do not changed to h2 as I was expecting. Can anyone provide some insight please?
Code: Select all
<?php
if (!$db) {die("Connection failed: " . mysqli_connect_error()); }
$sql2="SELECT id,body FROM articles WHERE id=2";
$result2=mysqli_query($db,$sql2);
$row2 = mysqli_fetch_array($result2);
if($row2) {$body2 = $row2['body']; }
$aboutcontent = preg_replace('/<h[1-6]>(.*?)<\/h[1-6]>/', '<h2>$body2</h2>', $body2);
echo substr($aboutcontent, 0, 500) . " ...";
?>