<?php
$test = "<!--my comment goes here--> Hello World ";
echo preg_replace('/\<.*?\>/','',$test);
?>
the code above echos hello world i want it to echo my comment goes here
<?php
$test = "<!--my comment goes here--> Hello World ";
echo preg_replace('/\<.*?\>/','',$test);
?>
the code above echos hello world i want it to echo my comment goes here
shouldn't preg_match be used for this? you basically want to extract a string, not replace it with another string...
You should be using preg_match
instead:
preg_match('/\<!--(.*?)-->/', $test, $m);
echo $m[1]; // here's your comment