Page 1 of 1

preg_match href

Posted: Sun May 07, 2006 1:55 pm
by patty06
HOw DO I use preg_match so that it checks to make sure it has <a href in a link.

Here is what I am using..

$recip = "http://www.mylink.com";
$conts = @file_get_contents($siteurl);

preg_match(?)

Posted: Sun May 07, 2006 2:21 pm
by timvw
And what have you tried already? What have you already researched yourself about regular expressions?

Posted: Sun May 07, 2006 5:20 pm
by Chris Corbyn
Have a look here: viewtopic.php?t=33147
And here: viewtopic.php?t=40169

;)

If all you're looking for is hyperlinks you should get by OK after a few swear words and a few lost hairs :P

Posted: Tue May 09, 2006 7:52 am
by dibyendrah
Here's the solution my fren !

Code: Select all

<?php
$url ="http://forums.devnetwork.net/index.php";
if (!preg_match('/^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\//i', $url)) {
     print "not valid url!";
} else {
    print "valid url";
} 

?>

Cheers,
Dibyendra