Current location: Hot Scripts Forums » Programming Languages » PHP » preg_match() url


preg_match() url

Reply
  #1 (permalink)  
Old 10-01-09, 05:28 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 706
Thanks: 0
Thanked 0 Times in 0 Posts
preg_match() url

Hi there..

I want to check a form entry if it is a "good" url.

There for I will make a pattern and check it with preg_match().
No I'm looking for a pattern to check for urls.

I took al look around the web and found the pattern below. but this
is not a "good" url.
PHP Code:

$website "http://www.site.com";

$patroon4 "~^https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?~";

if(!
preg_match($patroon4$website)) { echo"wrong"; } else { echo"good"; } 
where do I go wrong?
Reply With Quote
  #2 (permalink)  
Old 10-01-09, 08:56 AM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
This may work:

function CheckValidUrl(strUrl){
var RegexUrl = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
return RegexUrl.test(strUrl);
}


Or this:

function valid_url($str){
return ( ! preg_match('/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i', $str)) ? FALSE : TRUE;
}



Or this:

$valid = "^(https?|ftp)\:\/\/([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?[a-z0-9+\$_-]+(\.[a-z0-9+\$_-]+)*(\:[0-9]{2,5})?(\/([a-z0-9+\$_-]\.?)+)*\/?(\?[a-z+&\$_.-][a-z0-9;:@/&%=+\$_.-]*)?(#[a-z_.-][a-z0-9+\$_.-]*)?\$";
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Lil php coding help for url shortning script pede69 PHP 2 04-03-08 05:04 AM
URL Mapping of file locations GB Networks Web Servers 0 12-07-07 12:23 PM
Change this AJAX script to accomidate dynamic url arandlett JavaScript 3 06-14-06 03:01 AM
The Reasons Why do you Need URL Rewriting MODULE to Enchance your Web? handry PHP 11 08-05-05 07:32 AM


All times are GMT -5. The time now is 08:00 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.