Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $text = preg_replace("
- #((http|https|ftp)://(S*?.S*?))(s|;|)|]|[|{|}|,|"|'|:|<|$|.s)#ie",
- "'<a href="$1" target="_blank">$3</a>$4'",
- $text
- );
- var_dump(filter_var('example.com', FILTER_VALIDATE_URL));
- $pattern = "/b(?:(?:https?|ftp)://|www.)[-a-z0-9+&@#/%?=~_|!:,.;]*[-a-z0-9+&@#/%=~_|]/i";
- // Checks if string is a URL
- // @param string $url
- // @return bool
- function isURL($url = NULL) {
- if($url==NULL) return false;
- $protocol = '(http://|https://)';
- $allowed = '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)';
- $regex = "^". $protocol . // must include the protocol
- '(' . $allowed . '{1,63}.)+'. // 1 or several sub domains with a max of 63 chars
- '[a-z]' . '{2,6}'; // followed by a TLD
- if(eregi($regex, $url)==true) return true;
- else return false;
- }
- function url_exist($url){//se passar a URL existe
- $c=curl_init();
- curl_setopt($c,CURLOPT_URL,$url);
- curl_setopt($c,CURLOPT_HEADER,1);//get the header
- curl_setopt($c,CURLOPT_NOBODY,1);//and *only* get the header
- curl_setopt($c,CURLOPT_RETURNTRANSFER,1);//get the response as a string from curl_exec(), rather than echoing it
- curl_setopt($c,CURLOPT_FRESH_CONNECT,1);//don't use a cached version of the url
- if(!curl_exec($c)){
- //echo $url.' inexists';
- return false;
- }else{
- //echo $url.' exists';
- return true;
- }
- //$httpcode=curl_getinfo($c,CURLINFO_HTTP_CODE);
- //return ($httpcode<400);
- }
- if (preg_match("#^https?://.+#", $link) and @fopen($link,"r")) echo "OK";
- function is_valid_url ($url="") {
- if ($url=="") {
- $url=$this->url;
- }
- $url = @parse_url($url);
- if ( ! $url) {
- return false;
- }
- $url = array_map('trim', $url);
- $url['port'] = (!isset($url['port'])) ? 80 : (int)$url['port'];
- $path = (isset($url['path'])) ? $url['path'] : '';
- if ($path == '') {
- $path = '/';
- }
- $path .= ( isset ( $url['query'] ) ) ? "?$url[query]" : '';
- if ( isset ( $url['host'] ) AND $url['host'] != gethostbyname ( $url['host'] ) ) {
- if ( PHP_VERSION >= 5 ) {
- $headers = get_headers("$url[scheme]://$url[host]:$url[port]$path");
- }
- else {
- $fp = fsockopen($url['host'], $url['port'], $errno, $errstr, 30);
- if ( ! $fp ) {
- return false;
- }
- fputs($fp, "HEAD $path HTTP/1.1rnHost: $url[host]rnrn");
- $headers = fread ( $fp, 128 );
- fclose ( $fp );
- }
- $headers = ( is_array ( $headers ) ) ? implode ( "n", $headers ) : $headers;
- return ( bool ) preg_match ( '#^HTTP/.*s+[(200|301|302)]+s#i', $headers );
- }
- return false;
- }
- ^(http://|https://)(([a-z0-9]([-a-z0-9]*[a-z0-9]+)?){1,63}.)+[a-z]{2,6}
- (S*?.S*?)
- [a-z0-9]
- (?i)b((?:https?://|wwwd{0,3}[.]|[a-z0-9.-]+[.][a-z]{2,4}/)(?:[^s()<>]+|(([^s()<>]+|(([^s()<>]+)))*))+(?:(([^s()<>]+|(([^s()<>]+)))*)|[^s`!()[]{};:'".,<>?«»“”‘’]))
- preg_match("/(?i)b((?:https?://|wwwd{0,3}[.]|[a-z0-9.-]+[.][a-z]{2,4}/)(?:[^s()<>]+|(([^s()<>]+|(([^s()<>]+)))*))+(?:(([^s()<>]+|(([^s()<>]+)))*)|[^s`!()[]{};:'".,<>?«»“”‘’]))/", $url)
- (?xi)
- b
- ( # Capture 1: entire matched URL
- (?:
- https?:// # http or https protocol
- | # or
- wwwd{0,3}[.] # "www.", "www1.", "www2." … "www999."
- | # or
- [a-z0-9.-]+[.][a-z]{2,4}/ # looks like domain name followed by a slash
- )
- (?: # One or more:
- [^s()<>]+ # Run of non-space, non-()<>
- | # or
- (([^s()<>]+|(([^s()<>]+)))*) # balanced parens, up to 2 levels
- )+
- (?: # End with:
- (([^s()<>]+|(([^s()<>]+)))*) # balanced parens, up to 2 levels
- | # or
- [^s`!()[]{};:'".,<>?«»“”‘’] # not a space or one of these punct chars
- )
- )
Add Comment
Please, Sign In to add comment