Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsOtherProgramming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old February 12th, 2005, 04:28 AM
Scripter Scripter is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 2 Scripter User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 1 m 12 sec
Reputation Power: 0
PHP code to check, if a text has an url link

I am trying to put together a preg_match statement to check if a submited text has a valid url link.

Code:
 
if (preg_match('/(www.|)[-0-9A-Z]{2,63}[\.]{1,1}[A-Z]{2,4}(\.[A-Z]{2,4}|)/i',$text,$match)) echo "URL links are not allowed, please remove following URL link from the text: $match[0]<br>";

Reply With Quote
  #2  
Old February 12th, 2005, 06:30 AM
Lafinboy's Avatar
Lafinboy Lafinboy is offline
The Laughing Moderator
ASP Free Loyal (3000 - 3499 posts)
 
Join Date: Apr 2004
Location: Sydney, Australia
Posts: 3,267 Lafinboy User rank is Sergeant (500 - 2000 Reputation Level)Lafinboy User rank is Sergeant (500 - 2000 Reputation Level)Lafinboy User rank is Sergeant (500 - 2000 Reputation Level)Lafinboy User rank is Sergeant (500 - 2000 Reputation Level)Lafinboy User rank is Sergeant (500 - 2000 Reputation Level)  Folding Points: 29199 Folding Title: Starter FolderFolding Points: 29199 Folding Title: Starter Folder
Time spent in forums: 2 Weeks 1 Day 10 h 48 m 12 sec
Reputation Power: 15
Send a message via ICQ to Lafinboy Send a message via AIM to Lafinboy Send a message via MSN to Lafinboy Send a message via Yahoo to Lafinboy Send a message via Skype to Lafinboy
Was there a question in there? You seem to have it tied down pretty well. I would probably add http:// as part of the pattern, and use a bit of shorthand to keep things neater, like:
Code:
if (preg_match('/(http:\/\/|)(www.|)[\d\w-]{2,63}\.[A-Z]{2,4}(\.[A-Z]{2,4}|)/i',$text,$match)) echo "URL links are not allowed, please remove following URL link from the text: $match[0]<br>";

Reply With Quote
  #3  
Old February 14th, 2005, 08:57 AM
Scripter Scripter is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 2 Scripter User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 1 m 12 sec
Reputation Power: 0
Thanks. I don't know exactly what are the rules for domain names or is there any. What I know is that a domain can be 2-63 marks long, extension 2-4 chars and maximum total length of a domain is 67 marks. I posted the code here, if someone knows more.

URL can be also user.domain.ext or www.user.domain.ext so I added a check for that too.

Code:
 
if (preg_match('/(http:\/\/|)(www.|)([\d\w-]{1,63}\.|)[\d\w-]{2,63}\.[A-Z]{2,4}(\.[A-Z]{2,4}|)/i',$text,$match)) echo "URL links are not allowed, please remove following URL link from the text: $match[0]<br>";
Comments on this post
Phoenix disagrees: You cannot get "www.subdomain.domain.tld" domains

Reply With Quote
  #4  
Old March 7th, 2005, 03:43 PM
dieter.randolph dieter.randolph is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 1 dieter.randolph User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m
Reputation Power: 0
Similar question

Hello -- I want to do something very similar; I have a PHP app that draws plain text from a DB and renders it. At present, if the plain text contains a URL, the text is just sent to the screen. What I'd like to do is rewrite any URL's in the text as clickable links. Any guidance you can offer would be a big help.

Thanks,
Dieter

Reply With Quote
Reply

Viewing: ASP Free ForumsOtherProgramming Help > PHP code to check, if a text has an url link


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT