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

1
  • Since this is the syntax of a comment in html are you by any chance parsing an html document? Commented Aug 7, 2010 at 21:29

2 Answers 2

2

You should be using preg_match instead:

preg_match('/\<!--(.*?)-->/', $test, $m);
echo $m[1]; // here's your comment
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.