Как да проверя с регулярен израз дали резултатът е линк?

loscho

Registered
Привет,

Някой може ли да хелпне, как да проверя дали $link e линк с регулярен израз?

Благодаря
 
Код:
//URL: Different URL parts
//Protocol, domain name, page and CGI parameters are captured into backreferenes 1 through 4
'\b((?#protocol)https?|ftp)://((?#domain)[-A-Z0-9.]+)((?#file)/[-A-Z0-9+&@#/%=~_|!:,.;]*)?((?#parameters)\?[-A-Z0-9+&@#/%=~_|!:,.;]*)?'

//URL: Different URL parts
//Protocol, domain name, page and CGI parameters are captured into named capturing groups.
//Works as it is with .NET, and after conversion by RegexBuddy on the Use page with Python, PHP/preg and PCRE.
'\b(?<protocol>https?|ftp)://(?<domain>[-A-Z0-9.]+)(?<file>/[-A-Z0-9+&@#/%=~_|!:,.;]*)?(?<parameters>\?[-A-Z0-9+&@#/%=~_|!:,.;]*)?'

//URL: Find in full text
//The final character class makes sure that if an URL is part of some text, punctuation such as a 
//comma or full stop after the URL is not interpreted as part of the URL.
'\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]'
 
Май не го ползвам правилно

if(eregi("'\b((?#protocol)https?|ftp)://((?#domain)[-A-Z0-9.]+)((?#file)/[-A-Z0-9+&@#/%=~_|!:,.;]*)?((?#parameters)\?[-A-Z0-9+&@#/%=~_|!:,.;]*)?",$url))
{
$target_url=$url;
}
 
на мене това ми хрумна без регулярен израз
Код:
<?php  header( 'Content-Type:text/html; charset=UTF-8' );
$link = 'http://web-tourist.net/forum/viewtopic.php?t=104201';
$exp = explode('/',$link);
$exp1 = $exp[0];
if($exp1=='http:') {echo '<br>това е линк';}else {echo '<br>не е линк';}
?>
демек ако $link започва с http: ше изписва че е линк а ако не е че не е ... :D
 

Back
Горе