tags:

views:

35

answers:

2
<?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

A: 

shouldn't preg_match be used for this? you basically want to extract a string, not replace it with another string...

Quamis
+2  A: 

You should be using preg_match instead:

preg_match('/\<!--(.*?)-->/', $test, $m);
echo $m[1]; // here's your comment
quantumSoup