Tuesday, March 19, 2013

Install PHP man pages locally

Ah. Did you know you can install the PHP man pages onto your own little Unix machine? Only trouble is you have to become an PEAR expert first! Or you can just do this:
$ pear install doc.php.net/pman
Now it might complain that your PEAR needs updating, in which case you can usually just follow the suggestions to update and then try again. Once done, you can then access all the PHP documentation right from your command-line. Eg:
$ pman preg_match
There is an apropos(1) option, but it doesn't work and apparently never will because all the PHP man pages have "junk descriptions" (according to makewhatis) So to find functions, googling or searching php.net is going to be faster. Alternatively I've created this little script which can help: (save it as "pman" and put it somewhere in your PATH ahead of /usr/bin)
#! /bin/bash
# a pman replacement
# show php man page as per normal
# but if no exact man page, list all man pages with matching text

MAN=`which man`
$MAN -M /usr/lib/php/pear/docs/pman/ $*
if [ $? -ne 0 ]; then
 echo ""
 echo "Listing commands matching: $*"

 cmds=$( ls /usr/lib/php/pear/docs/pman/man3 | grep "$*" | sed 's/.[0-9].gz//' )
 select cmd in $cmds
 do
  $MAN -M /usr/lib/php/pear/docs/pman/ $cmd
  break
 done
fi
So now, if you run:
$ pman some_man_page
it will show the man page as usual. But if you run say:
$ pman tags
you get:
No manual entry for tags

Listing commands matching: tags
1) get_meta_tags
2) strip_tags
#?
Now you can just type the number (in this case 1 or 2) to see the man page.
BTW, if you check, you'll see that all pman does is this:
#!/bin/sh
MAN=`which man`
$MAN -M /usr/lib/php/pear/docs/pman/ $*
Which means all you have to do is add something like:
export MANPATH=/usr/share/man:/usr/lib/php/pear/docs/pman
to your Shell startup file and you'll be able to access the PHP man pages with man just like any other man page.

No comments:

Post a Comment