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

ruby - How do I merge two hashes into a hash of arrays? -

c++ - Do gcc's __float128 floating point numbers take the current rounding mode into account? -