in Technology

Setting up local copy of PHP manual – with smart lookups

If you are a PHP developer, you probably know that you can type “php.net/substr” to look at documentation for the substr() function. This works for many other keywords as well and is a superb feature. It’s just so convenient, I stopped using my local copy of PHP manual.

But yesterday, I wanted it offline. I downloaded the “many HTML files” version of the documentation, extracted it and set it up on my local Apache. I can now open up http://localhost/phpman/ to read the documentation. (this is how I actually learned PHP 11 years ago!!)

And I wanted the smart lookups – auto complete! I searched around to find if there was a ready .htaccess file that I could use. Or if someone had made something similar already. I did not really find anything solid. Suddenly I realized I can just look up the PHP.net site source code and figure out what they are doing, and replicate it on my local setup. (Yes, PHP.net’s source code is open too!)

Eureka!

So after a few minutes of hacking around, I have my nice little setup that mimics PHP.net’s quick / smart lookup of functions. Typing http://localhost/phpman/substr takes me to http://localhost/phpman/function.substr.html in a split second.

Jai ho!

Let me jump to the code now that you’ve read so much!

Here’s the .htaccess file. And here’s the PHP file – “manual-lookup.php” placed in the phpman folder. The file is an adaptation from php.net website’s source.

Here’s the complete procedure:

  1. Ensure you have Apache / PHP setup locally.
  2. Download the many HTML files version of PHP documentation.
  3. Extract it in a folder called “phpman” in your website root. You should now be able to see it at http://localhost/phpman
  4. Download this file, and save it as .htaccess within the phpman folder.
  5. Download this file, and save it as manual-lookup.php within the phpman folder.
  6. Try http://localhost/phpman/substr – it should work if all went well!
  7. Enjoy!

Hope this helps someone like me 😉

Write a Comment

Comment

  1. Interesting article. In order to prevent the URL in my browser from changing, I switch the code which was sending the header to:

    // Find the page from pattern and language
    if ( ” == ($page = find_manual_page($_GET[‘lang’], $_GET[‘pattern’])) ) {
    $page = ‘index.html’;
    }
    print include basename($page);

    As I am literally printing the manual page (instead of redirecting from within PHP), the browser’s URL will remain as type. This will make it easier to hack and/or fix typos.

    I also grabbed the latest manual-lookup.php from php.net. It took me awhile to figure out how you come up with the correct list of sections. Then I found the php.net version in the site.inc.

    Overall, very will written article. Good topic to make you think about … how DID they do that.

    Thank you,
    B

  2. Hmmm … I just looked at the bottom of my redirected page and found that it was including the result of the print statement (a “1” … true).

    Changed to just include the html page and looks great!

    / Find the page from pattern and language
    if ( ” == ($page = find_manual_page($_GET[‘lang’], $_GET[‘pattern’])) ) {
    $page = ‘index.html’;
    }
    include basename($page);