Tag Archive for url

Get current page url

<?php
function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "<a href="://";" >://";</a>
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}
?>
You can now get the current page URL using the line:

<?php
  echo curPageURL();
?>
Sometimes it is needed to get the page name only. The following example shows how to do it: 

<?php
function curPageName() {
 return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
}

echo "The current page name is ".curPageName();
?>

source

News Module in Typolight: add year and month in the url

//print_r(date('Y',$objArticle->date));
setlocale(LC_TIME, "de_DE");
$monat = strftime('%B',$objArticle->date);
if ($monat == 'März') $monat = 'Maerz';
$strUrl = ampersand($this->generateFrontendUrl($objPage->fetchAssoc(), '/'.date('Y',$objArticle->date).'/'.$monat.'/items/' . ((!$GLOBALS['TL_CONFIG']['disableAlias'] && strlen($objArticle->alias)) ? $objArticle->alias : $objArticle->id))/*.'?year=2009'*/);

source

Переход на урл при помощи яваскрипта

location.href="<a href="http://www.html.by";

" >http://www.html.by";
source

Form json to url

var JSON = {
	parms : function(a1){t=[];for(x in a1)t.push(x+"="+encodeURI(a1[x]));return t.join("&");}
};


// EXAMPLE
var object = {
	'parm1' : 'val1',
	'parm2' : 'val2',
	'parm3' : 'val3'
};

var con = JSON.parms(object); // return: parm1=val1&parm2=val2&parm3=val3

source

HAProxy URL Rewriting

frontend webserver
bind    :80
mode    http
acl is_www hdr_beg(host) -i     <a href="http://www.domain.com" >www.domain.com</a>
use_backend http_cluster if is_www
default_backend http_redir

backend http_redir
mode    http
balance source
option  nolinger
server  web 127.0.0.1:8080 redir <a href="http://www.domain.com" >http://www.domain.com</a>

backend http_cluster
mode    http
option  forwardfor
balance source
option  httpclose
option  httpchk HEAD / HTTP/1.0
server  web01 172.16.0.11:80 weight 1 check inter 1000 rise 5 fall 1
server  web02 172.16.0.12:80 weight 1 check inter 1000 rise 5 fall 1
server  web03 172.16.0.13:80 weight 1 check inter 1000 rise 5 fall 1
server  web04 172.16.0.14:80 weight 1 check inter 1000 rise 5 fall 1

source

magento url per php

<?php echo Mage::getBaseUrl();  ?>

source

formatWebAddress

function formatWebAddress($webAddress) {
$originalWebAddress = $webAddress;
$webAddress = "*" . $webAddress;
$formattedWebAddress = "";
if (stripos($webAddress, "http://") == 1) {	//starts with <a href="http://" >http://</a>
if (substr_count($webAddress, ".") == 1) {	//one dot only
$formattedWebAddress = $originalWebAddress;
$formattedWebAddress = insertString($formattedWebAddress, "www.", 7);
}
else
$formattedWebAddress = $originalWebAddress;
}
else {	//does not start with <a href="http://" >http://</a>
if (substr_count($webAddress, ".") == 1)	//one dot only
$formattedWebAddress = "http://www." . $originalWebAddress;
elseif (substr_count($webAddress, ".") >= 2)	//two dots only
$formattedWebAddress = "http://" . $originalWebAddress;
else
$formattedWebAddress = $originalWebAddress;
}
// add slash at end
if (substr_count($formattedWebAddress, "/") == 2)	//if it has "//" at beginning
$formattedWebAddress .= "/";
$formattedWebAddress = strtolower($formattedWebAddress);
return $formattedWebAddress;
}

source

Look Up a Company’s 401k Plan Rating from BrightScope

import re

from urllib import urlopen
from urllib import urlencode

"""
Author: <a href="mailto:bing.jian@gmail.com">bing.jian@gmail.com</a>
Date:  2009/07/25
Example Usage:

>>> import brightscope
>>> o = brightscope.get_directory()
>>> brightscope.query_score(o,'southwest')
Found Southwest Airlines Co. (3)
BrightScope Rating: 86
Found Southwest Electric Company (2)
BrightScope Rating: 55
Found Southwestern Energy Company
BrightScope Rating: 65
Found Southwest Water Company (2)
BrightScope Rating: 66
Found Southwest Gas Corporation
BrightScope Rating: 69
Found Southwestern/Great American, Inc.
BrightScope Rating: 52

"""

home_url = 'http://www.brightscope.com/'
rating_base_url = 'http://www.brightscope.com/401k-rating/'
directory_url = 'http://www.brightscope.com/ratings/'

company_string = '<li ><a href="/401k-rating/(?P<link>.+?)/"[s]+>(?P<name>.+?)</a></li>'
company_pattern = re.compile(company_string,re.MULTILINE)

top_company_string = '<li class="top.+?"><a href="/401k-rating/(?P<link>.+?)/"[s]+title=".+?"[s]+>(?P<name>.+?)</a></li>'
top_company_pattern = re.compile(top_company_string,re.MULTILINE)

score_string = '<span id="your_plan_rating">(?P<score>[0-9]+)</span>'
score_pattern = re.compile(score_string)

amp_pattern = re.compile(r'&amp;')
prime_pattern = re.compile(r'&#39;')


def get_directory():
doc = urlopen(directory_url).read()
res = {}
patterns = [company_pattern, top_company_pattern]
for pattern in patterns:
o = pattern.finditer(doc)
for item in o:
link, company = item.groups()
amp = amp_pattern.search(company)
if amp:
company = amp_pattern.sub('&',company)
prime = prime_pattern.search(company)
if prime:
company = prime_pattern.sub("'",company)
res[company] = link
return res


def query_score(directory, key):
for company in directory:
if key.lower() in company.lower():
print "Found %s"%company
url = rating_base_url + directory[company]
doc = urlopen(url).read()
o = score_pattern.search(doc)
if o:
print "BrightScope Rating: %d"%int(o.groups()[0])

source

A Better Snipplr Bookmark

javascript:if(!confirm('Add%20to%20Snipplr?'))window.open('http://snipplr.com').focus();else(function()%7Bvar%20x=document.getElementsByTagName('head').item(0);var%20o=document.createElement('script');if(typeof%20o!='object')o=document.standardCreateElement('script');o.setAttribute('src','http://snipplr.com/bookmarklets/'+(navigator.userAgent.indexOf('Firefox')+1?'firefox':'safari')+'.js');o.setAttribute('type','text/javascript');x.appendChild(o);%7D)();

source

URL encoding

NSString* escapedUrl = [originalUrl
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]

source