0
if(preg_match("//*/i",$line))echo "comment start";
if(preg_match("/*//i",$line))echo "comment end";

I'm searching comments which one starts with /* and end with */ and I cant get any result with this code. I’m trying to get comment start and end line.

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103

2 Answers2

1

Try this:

$line = '/* Hello, world! This is a comment! */';

if (preg_match("/^\/\*(.*)/i", $line)) echo "comment start";
if (preg_match("/(.*)\*\/$/i", $line)) echo "comment end";

You need to escape out slashes like / with a \ preceding it. Otherwise it’s interpreted as part of the regex logic & not something you are looking for. But that said, unclear what you want to get out of matching the beginning & ending parts of the comment.

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
0

try this:

 if (preg_match('/\\\\\*/i', $line)) echo "comment start";  
 if (preg_match('%\*/%i', $line)) echo "comment end";
Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268