What you should know (and where you should begin your searching) is tha preg_* functions use Perl Compatible Regular Expressions (aka PCRE) and the ereg_* functions use POSIX functions. Reality is you should really only concern yourself with PCRE's because, aside from Apache 1.3, everything else pretty much uses PCRE. [url=http://regexlib.com/]Here[/url is a resource you should bookmark. It is geared toward DOT-NET, but DOT-NET uses PCRE as well so syntax is identical.
Now how to use the actual preg_* functions? This is something you will look at php.net for.
Say you have a preg_match.
PHP Code:
preg_match('#\[some text](.+)\[goes here]#i',$text);
That will hypothetically match:
- Some Text about me goes here.
- Some text describing ridiculous matters of life and death goes here
- SoMe TeXt make me go blah goes hERE too
But not just:
Some text goes here.
Now say you wanted to search a whole paragraph for a single phrase and echo it into a string. You'd use preg_replace because you are replacing the whole block of text with something else.
PHP Code:
$snippet = preg_replace('#\[some text](.+)\[goes here]#i',"$1",$paragraph);
Now:
There's plenty of things to consider. Really, the bottom line is that the decision isn't yours to make. You may want some text that you feel goes here to reflect those sentiments.
Becomes:
By using $1, in the replace area, I am saying that I want to take the first matched grouping (which was the (.+)).
It's all very complex and you'll have to read about it, but that's a brief overview...
Aaron
Bookmarks