preg_match href

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
patty06
Forum Newbie
Posts: 10
Joined: Wed May 03, 2006 1:21 pm

preg_match href

Post 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(?)
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

And what have you tried already? What have you already researched yourself about regular expressions?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post 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
Post Reply