Help! What do these regular expression mean?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Peniel
Forum Newbie
Posts: 2
Joined: Sun Jul 18, 2010 10:17 pm

Help! What do these regular expression mean?

Post by Peniel »

Hello. Can anyone explain to me the regular expressions in this code? It was part of a search engine code.

Code: Select all

/* Remove whitespace from beginning and end of string: */
    $buf = trim($buf);
    /* Try to remove all HTML-tags: */
    $buf = strip_tags($buf);
    $buf = ereg_replace('/&\w;/', '', $buf);
    /* Extract all words matching the regexp from the current line: */
    preg_match_all("/(\b[\w+]+\b)/",$buf,$words);
Thanks.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Help! What do these regular expression mean?

Post by AbraCadaver »

in the ereg_replace() &\w; replace the following with nothing ''
[text] any & followed by a word character followed by ;[/text]
in the preg_match_all() \b[\w+]+\b match the following and put each full match into the $words array:
[text] a word boundary followed by one or more (word characters or +) followed by a word boundary[/text]

Word characters are:
[text] letters, numbers and _[/text]
A word boundary is:
[text] Before the first character in the string, if the first character is a word character.
After the last character in the string, if the last character is a word character.
Between two characters in the string, where one is a word character and the other is not a word character.[/text]
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Peniel
Forum Newbie
Posts: 2
Joined: Sun Jul 18, 2010 10:17 pm

Re: Help! What do these regular expression mean?

Post by Peniel »

Thank you, abraCadaver, for your reply.
Post Reply