Create a  PHP Documentation Bookmarklet

Raven

Create a PHP Documentation Bookmarklet

Most PHP programmers I know (including myself) visit the PHP function reference daily, if not hourly. Going to http://php.net/ is a quick way to lookup the specs on a particular function, reserved word, or anything else in the language. Here’s an easy javascript tip that’ll make looking up PHP functions even faster.

Just drag this link to your browser’s bookmark bar. Now, when you click on it, you’ll be prompted to enter a function name. Hit enter, and you’ll be automagically taken to the correct PHP reference page.

But we’re not done yet! If you’re using Apple’s Safari browser we can even do this without using the mouse. Press command + <1…9> to jump straight to a specific bookmark. For example, command+3 will jump to the 3rd bookmark listed in your bookmark bar. So, stick our PHP bookmarklet in a 1 – 9 spot and you can do lookups without ever taking your hands off the keyboard.

So how does this magic bookmark work? The bookmark we added is really two lines of embedded javascript. The first line

var func = prompt("Enter a PHP function", "date");

prompts the user to enter a function name to lookup. In this example I’ve also given the prompt a default value of “date” since that is the function I visit most often. You can leave that field blank or fill it in with your own value.

The second line

window.open('http://php.net/' + func);

tells the browser to go to http://php.net/ followed by the value you entered.

To complete the process we put both lines together with “javascript:” in front and bookmark the link.

Related Posts Plugin for WordPress, Blogger...

Tell us what you think

4 Responses to “Create a PHP Documentation Bookmarklet”

  1. ninware says:

    wow nice idea thanks

  2. Rudolf says:

    Original script does not correctly processes CANCEL button in dialog and does not handle empty imput. Here is an improved version:
    javascript:var func=prompt(“PHP Function”);if((func!=null)&&(func!=”)) window.open(“http://php.net/”+func)
    If user clicks CANCEL or does not input anything, nothing will happen.

  3. Tyler Hall says:

    Aha! Great idea, Chris. I had previously added a PHP search to my Firefox search box, but never even thought about doing it for Opera. I’m going to add your code in right now :)

  4. Chris Wage says:

    While we’re at it, you can do this sort of thing with Opera, too, using their “quicksearches”. This will let you do “p sprintf” in the address bar:

    [Search Engine 10]
    Name=&PHP
    URL=http://php.net/%s
    Query=
    Key=p
    Is post=0
    Has endseparator=0
    Encoding=utf-8
    Search Type=1
    Position=-1
    Nameid=0

Leave a Reply

You must be logged in to post a comment.