|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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>";
|
|
#2
|
||||
|
||||
|
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>";
__________________
-
thought-after | my thoughts on web development Get Firefox, the developers browser Budget hosting - recommended [/left] |
|
#3
|
|||
|
|||
|
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>";
|
|
#4
|
|||
|
|||
|
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 |
![]() |
| Viewing: ASP Free Forums > Other > Programming Help > PHP code to check, if a text has an url link |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|