Sep

4


You can use this PHP regular expression to search for a word in code and to make sure the word is found within comments. The string // WORD will match on a line and so will /* WORD */.


<html>
<head><title>Searching for words within comments</title></head>
<body>
<form action="<?= $_SERVER['PHP_SELF']; ?>" method="post">
<input type="text" name="str"
value="<?php print $_POST['str'];?>" /><br />
<input type="submit" value="Find WORD in comments" /><br /><br />
<?php
if ( $_SERVER['REQUEST_METHOD'] == "POST" )
{
$str = $_POST['str'];
if ( preg_match( "/^(?:\/\*(?:(?!\*\/).)*|\/\/.*?)WORD/", $str ) )
{
print "<b>Found WORD in comments: &nbsp;'" . htmlspecialchars($str)
.."'</b><br/>";
}
else
{
print "<b>Found no match in text: &nbsp;'" .
htmlspecialchars($str) . "'</b><br/>";
}

}
?>
</form>
</body>
</html>


Similar Posts

Comments

Name (required)

Email (required)

Website

Speak your mind

2 Comments so far

  1. krantit on September 5, 2008 6:56 am

    This is a very useful article, i think that’s how wordpress reads plugin info.

  2. orircuize on December 8, 2008 12:29 pm

    Привет, я думала что это совсем не так происходит:)

    ——————————————-
    Мой блог: http://medved-vyshivka.blog.ru/

Sponsors




Links