Tag Archive for url

Full url without variables

<?
function full_url()
 	{
 $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
 $protocol = substr(strtolower($_SERVER["SERVER_PROTOCOL"]), 0, strpos(strtolower($_SERVER["SERVER_PROTOCOL"]), "/")) . $s;
 $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
 $address = $protocol . "<a href="://"" >://"</a> . $_SERVER['SERVER_NAME'] . $port . $_SERVER['REQUEST_URI'];
 $parseUrl = parse_url(trim($address));
 return $parseUrl['scheme'].'<a href="://'.$parseUrl['host'].$parseUrl['port'].$parseUrl['path'];" >://'.$parseUrl['host'].$parseUrl['port'].$parseUrl['path'];</a> 
 	}
?>

source

regex url parser

/^((http[s]?|ftp):/)?/?([^:/s]+)(:([^/]*))?((/w+)*/)([w-.]+[^#?s]+)(?([^#]*))?(#(.*))?$/gi

schema = 2,
domain = 3,
port = 5,
path = 6,
file = 8,
querystring = 9,
hash = 12

source

Easily Target a URL with the Window Method of Your Choice

// gotoLink takes 3 parameters: the event, the URL string, and the method (_self, _blank, etc)
//
// sample usage:
// gotoLink( evt, "<a href="http://google.com"," >http://google.com",</a> "_blank" );


function gotoLink( evt:Event, l:String, meth:String  ) : void
{
	var URLReq:URLRequest = new URLRequest(l);
	try 
	{
		navigateToURL(URLReq, meth);
	} catch (e:Error) 
	{
		trace(e);
	}
}

source

Drupal print url args

<?php

print '<div align="left">';
print '<br/>arg-0 :' .arg(0);
print '<br/>arg-1 :' .arg(1);
print '<br/>arg-2 :' .arg(2);
print '<br/>q:' . $_GET['q'];

$view = $GLOBALS['current_view'];
$args = $view->args;

print '<br/>args-0 :' .$args[0];
print '<br/>args-1 :' .$args[1];

print '</div>';

?>

source

Short URL Function with PHP

<?php
function shorturl($url){
    $length = strlen($url);
    if($length > 45){
        $length = $length - 30;
        $first = substr($url, 0, -$length);
        $last = substr($url, -15);
        $new = $first."[ ... ]".$last;
        return $new;
    }else{
        return $url;
    }
}
?>

// USAGE

<?php

$longurl= "<a href="http://www.google.com/search?q=symfony+project&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:tr:official&client=firefox-a";" >http://www.google.com/search?q=symfony+project&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:tr:official&client=firefox-a";</a>
$shorturl = shorturl($longurl);
echo "<a href="$longurl">$shorturl</a>";


?>

source

Retrieve The Original URL From A Shortened URL

<?php
function retrieve_shortened_link($shortUrl){
	$headers = get_headers($shortUrl, 1);
	if(is_array($headers['Location'])){
		return $headers['Location'][0];
	}else{
		return $headers['Location'];
	}
}
?>

source

Get Internal URL from URL Alias

<?php drupal_lookup_path('source',$url_alias); ?>

source

Link to specific part of YouTube file

<a href="http://www.youtube.com/watch?v=UkTQwP2gFxU#t=3m14s

" >http://www.youtube.com/watch?v=UkTQwP2gFxU#t=3m14s
source

check url on delicious

javascript:location.href="<a href="http://delicious.com/url/view?url="%20+%20location.href;

" >http://delicious.com/url/view?url="%20+%20location.href;
source

Zend Router simple extension through simple regex

/**
* Add this in your bootstrap
*/
protected function _initRoutes() {
    
            $ctrl = Zend_Controller_Front::getInstance();
            $router = $ctrl->getRouter();
            //match every call on <a href="http://ZEND_ROOT/aZ2s-Ty9" >http://ZEND_ROOT/aZ2s-Ty9</a>
            $route = new Zend_Controller_Router_Route_Regex('([a-zA-Z0-9]+-[a-zA-Z0-9]+)',
                array(
                    //dispatch this to the VController
                    'controller' => 'v',
                    // iAction()
                    'action'     => 'i'
                    ),
                array(
                    //send the captured value has the "e" parameters of the request
                    1 => 'e'
                    )
            );
    
            //give a name to your route and add it to the default router
            $router->addRoute('view',$route);
        }

source