Page 1 of 1

Help! What do these regular expression mean?

Posted: Sun Jul 18, 2010 11:05 pm
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.

Re: Help! What do these regular expression mean?

Posted: Sun Jul 18, 2010 11:35 pm
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]

Re: Help! What do these regular expression mean?

Posted: Tue Jul 20, 2010 10:06 pm
by Peniel
Thank you, abraCadaver, for your reply.