Jared Quinn

IT Consulting :: Design :: Events Management

Archive for November, 2005


URL Function Enhancements


One of the most commonly code snippets i’ve needed in both Perl and PHP over the years has been a function to neatly split URLs. While PHP’s parse_url function does this nicely; I also wanted to be able to echo a single piece of that result and enhance it with some commonly used ones.

The first function is fairly straight forward, build a URL out of the $\_SERVER global bits. This can be used with the second function for returning more interesting things. The parameter for get\_myurl() is an indication of wether the result should be echo’d or returned (a-la WordPress functions).

function get_myurl($v = false) {
    $res = ( $_SERVER[‘HTTPS’] ? ‘https://’ : ‘http://’ ) .
                 $_SERVER[‘HTTP_HOST’] .
                 $_SERVER[‘REQUEST_URI’];
    if(!$v) { echo $res; } else { return $res; }
  }

The second function is split\_url which is my enhancement on PHP’s builtin parse\_url.

It may be called like:

<?php split_url(‘’, ‘relpath’, true); ?>

(Note: relpath is the relative path for the URL supplied (or from get\_myurl() if no URL is supplied), it is the path that any documents referenced in the current document would be relative to, unless a base href is supplied in the output.)

function split_url($url = ‘’, $component = ‘’, $v = false) {
    if($url == ‘’) { $url = get_myurl(true); }
    $res = parse_url($url);
    $res[‘fullpath’] = $res[‘path’];
    $paths = explode(‘/’, $res[‘fullpath’]);
    $res[‘file’]  = array_pop($paths);
    $res[‘path’]  = implode(‘/’, $paths);
    list($res[‘noquery’], $junk) = explode(‘/’, $res[’scheme’], 2);
    $res[‘relpath’] = $res[’scheme’] . ‘://’;
    if($res[‘username’]) { $res[‘relpath’] .= $res[‘user’] . ‘:’ . $res[‘pass’] . ‘@’; }
    $res[‘relpath’] .= $res[‘host’] . $res[‘path’] . ‘/’;
    if($component) {
      if($v) { echo $res[$component]; return } else { return $res[$component];   
    }
    return($res);
  }

split\_url() with no arguments would return a associate array of all parts of the current URL.

Image Submit and New Windows


“I’m wondering if you could help me. I have an image and i need to give it this as it’s link <input type=submit value=Login>, how can i do it, any ideas? Is there any chance i can get it so it opens in a new window?”

Firstly, without me ranting, I really do not like anything that opens in a new window, unless it is part of an web based application, has a good reason to do so and the action is not unexpected for the user. Apart from that on with answering your question.

The first part is easy, standard HTML, something like the below code snippet should do exactly what you want.

<input type=“image” name=“submit” value=“login” src=“/image.jpg” />

Now to open your form in a new window. I personally think using JavaScript is the best way to do this.

Let’s define a function to do it. This can be inserted anywhere in your HTML.

<script language=“JavaScript”>
<!–
function openWin() {
  var p = window.open(‘’,‘popUp’,’scrollbars=no,resizable=no,h=100,w=200′);
  document.MyForm.target = ‘p’;
}
//–>
</script>

Now we put our form together, noting that the form’s name is the same as the one used in our function.

<form method=“post” name=“MyForm” action=“dest.php” onSubmit=“openWin();”>
<input type=“image” name=“submit” value=“login” src=“/image.jpg” />
</form>

I hope this answers your question sufficiently.

New Layout Complete


Testing is now underway on the new layout for the site which is a pure CSS based, 2 column, content first layout.

It involves the usual struggle with browser compatibility issues all of which as usual are caused by Microsoft’s Internet Explorer. Once testing of the new layout is completed and i’ve finished tweaking it full details of how it was achieved will be posted.

The site is tested most with my browser of choice, Firefox 1.0.6 under Linux.

An End to 2005


I will be uncontactable by telephone or online for the next few weeks as I am heading out of Sydney for an end of year get-a-way.

I should be returning just before Christmas, or at the very latest the beginning of 2006. All current clients have been provided alternative contacts to handle any issues that may arise during my holidays.

If you have any enquiries for projects for 2006 please feel free to email me, and I will get back to you once I return.

I would however like to take this opportunity to wish all my current clients a very merry Christmas and a prosperous 2006.