Jump to content

Archived

This topic is now archived and is closed to further replies.

Ninjakreborn

regular expressions

Recommended Posts

What are the purposes of the following< please note I have done extensive research, I found alot of tutorials telling me about them, how to utilize them, this is great, but what is the "purpose" of them, in general programming when will the "need" arise for me to have to use it
preg_match()
preg_matchall()
and other things of those nature, if you have some ideas I would appreciate it, if I know there is a reason then we can work something.

Share this post


Link to post
Share on other sites
Regular expression allow you to check/manipulate large strings based on very small parts of it.

An example -

Like this site where ever someone enters the word 'php' you want to link it to php.net

string is "I progam in php because it is not made by microsoft and its dead nice and you can do loads with php."

$string = preg_replace('/(php)(\.| )/','<a href="http://www.php.net">\\1</a>\\2',$string);

should return...

I progam in <a href="http://www.php.net">php</a> because it is not made by microsoft and its dead nice and you can do loads with <a href="http://www.php.net">php</a>.

Basically it allows you to control all manner of aspects of the string or get all manner of info from a string based on small parts of it without you having to know the exact content of the string before hand.

Share this post


Link to post
Share on other sites
thanks that gives me some ideas on test programs to learn, I appreciate the "example" thanks.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.