php - preg_replace is replacing matches including content contained within -


i using preg_replace replace html comment tags empty space seems replacing whole html comment empty space.

    echo preg_replace('/<!--(.*?)-->/','',$r->pagecont); 

where $r->pagecont database entry containing html, example:

    <div class="col-lg-12">     <p>the year is:</p>     <!-- <?php echo date(y); ?> -->     </div> 

in above example, html comment tags stripped away leaving php code echo year. said, happening entire html comment being stripped away.

can recommend pattern use? appreciate input.

edit: updated question reflect code using.

it seems you're trying replace comment line php code present inside that. if yes, need put replacement string $1 refer group index 1.

echo preg_replace('/<!--(.*?)-->/', '$1', $r->pagecont); 

demo


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -