言語
サーバ関連
ツール
API
読み物
その他
[AD]
備忘録用のWikiです。主にWeb技術方面や、iOSやAndroidなどスマホアプリ開発周りをメモしています(する予定ですw)。
= 2016/04/10:デザインを変更しました。 = 2016/03/27:2001年ごろに執筆していた「[[webp:|Webプログラミング]]」を掲載しました。 = 2016/03/27:日本語が入ったURLを、英数字の文字列に変更しました。旧URLからはリダイレクトがかかります。 = 2016/03/22:さぼっていた更新を再開しました = 2014/08/??:旧サイト(katsubemakito.net/cgiperl/)からの引越しを行いました
PHPの公式ドキュメント(マニュアル)は環境さえ用意すれば自分でビルドすることができます。
DocBookと呼ばれる仕組みが採用されており、HTML以外にも様々なフォーマットに出力できるため、例えばPDFやePubを生成し、KindleやiBooksなどの電子書籍リーダーで閲覧することも可能です。
PHPのドキュメントを生成するコマンド「PhD」のインストールを最初に行います。PEARが利用できればそれほど難しくはありません。
$ pear channel-discover doc.php.net Channel "doc.php.net" is already initialized $ sudo pear install doc.php.net/phd_php Did not download optional dependencies: phpdocs/PhD_PEAR, phpdocs/PhD_IDE, use --alldeps to download automatically phpdocs/PhD_PHP can optionally use PHP extension "haru" phpdocs/PhD can optionally use package "phpdocs/PhD_PEAR" phpdocs/PhD can optionally use package "phpdocs/PhD_IDE" phpdocs/PhD can optionally use PHP extension "haru" phpdocs/PhD_Generic can optionally use PHP extension "haru" downloading PhD_PHP-1.1.10.tgz ... Starting to download PhD_PHP-1.1.10.tgz (26,240 bytes) .........done: 26,240 bytes downloading PhD-1.1.10.tgz ... Starting to download PhD-1.1.10.tgz (47,401 bytes) ...done: 47,401 bytes downloading PhD_Generic-1.1.10.tgz ... Starting to download PhD_Generic-1.1.10.tgz (29,362 bytes) ...done: 29,362 bytes install ok: channel://doc.php.net/PhD_Generic-1.1.10 install ok: channel://doc.php.net/PhD-1.1.10 install ok: channel://doc.php.net/PhD_PHP-1.1.10
$ phd --version PhD Version: 1.1.10 Generic: 1.1.10 PHP: 1.1.10 PHP Version: 5.5.9-1ubuntu4.14 Copyright(c) 2007-2016 The PHP Documentation Group
$ svn co http://svn.php.net/repository/phpdoc/modules/doc-en phpdoc-en
上記だと英語のドキュメントになる。日本語のドキュメントがほしい場合は、http://svn.php.net/repository/phpdoc/modules/doc-ja
をcheckoutする。
phd用の.manual.xmlを生成する。生成が完了したらctrl+c
で終了する。
$ cd phpdoc-en $ php doc-base/configure.php configure.php: $Id: configure.php 337463 2015-08-14 23:54:15Z cmb $ PHP version: 5.5.9-1ubuntu4.14 Checking for source directory... /home/ubuntu/phpdoc-en/doc-base Checking for output filename... /home/ubuntu/phpdoc-en/doc-base/.manual.xml Checking whether to include CHM... no Checking for PHP executable... /usr/bin/php5 Checking for language to build... en Checking whether the language is supported... yes Checking for partial build... no Checking whether to enable detailed XML error messages... no Checking libxml version... 2.9.1 Checking whether to enable detailed error reporting (may segfault)... yes Checking whether to optimize out the DTD (performance gain, but segfaults)... yes Generating /home/ubuntu/phpdoc-en/doc-base/manual.xml... done Generating /home/ubuntu/phpdoc-en/doc-base/install-unix.xml... done Generating /home/ubuntu/phpdoc-en/doc-base/install-win.xml... done Generating /home/ubuntu/phpdoc-en/doc-base/developer.template.xml... done Generating /home/ubuntu/phpdoc-en/doc-base/scripts/file-entities.php... done Iterating over extension specific version files... OK Saving it... OK Creating file /home/ubuntu/phpdoc-en/doc-base/entities/file-entities.ent... done Checking for if we should generate a simplified file... no Checking whether to save an invalid .manual.xml... no Loading and parsing manual.xml... done. Validating manual.xml... done. All good. Saving .manual.xml... done. All you have to do now is run 'phd -d /home/ubuntu/phpdoc-en/doc-base/.manual.xml' If the script hangs here, you can abort with ^C. _ _..._ __ \)` (` / / `\ | d b | =\ Y =/--..-="````"-. '.=__.-' `\ o/ /\ \ | | \ \ / ) \ .--""`\ < \ '-' / // | || \ '---' jgs ((,,_/ ((,,___/ (Run `nice php configure.php` next time!) ^C
.manual.xmlを使用し、phdでドキュメントを生成します。後は待つだけです。
$ phd -d doc-base/.manual.xml -P PHP
環境によってはかなりの時間がかかります。また警告などが表示され心が休まらないかもしれませんが、気長に待ちましょう。
もしお目当てのファイル形式がわかっているのであれば、-f
で指定するのも手です。
$ phd --help -f <formatname> --format <formatname> The build format to use
ドキュメントはすべてoutputディレクトリに生成されます。
$ cd output $ ls index.sqlite php-bigxhtml.html php-chunked-xhtml/ php-epub/ php-howto/ php-pdf/ php-web/ php-bigxhtml-data/ php-chm/ php-enhancedchm/ php-functions/ php-kdevelop php-tocfeed/
以下のエラーは、PDFを生成する際に使用するライブラリが存在しないために発生する。
PHP Fatal error: Class 'HaruDoc' not found in /usr/share/php/phpdotnet/phd/Format/Abstract/PDF.php on line 138
libHaruを公式サイトからダウンロードしインストール、その後PHPで利用するためにPECLで必要なライブラリを入れます。
$ wget -O libharu.tar.gz https://github.com/libharu/libharu/tarball/master $ tar zxvf libharu.tar.gz $ cd libharu-libharu-d84867e $ ./buildconf.sh (./configureが存在しない場合に実行。これで生成される) $ ./configure $ make clean $ make $ sudo make install $ sudo pecl install haru
以降は環境によって設定方法が異なりますが、コマンドラインでPHPの拡張機能を有効にする設定を行う。ここでは個別のファイルに書いていますが、php.iniへ直接書いてもOK。
$ sudo vi /etc/php5/mods-available/haru.ini extension=haru.so $ cd /etc/php5/cli/conf.d $ sudo ln -s ../../mods-available/haru.ini haru.ini
$ git reset HEAD hello.txt $ git checkout hello.txt
git reset HEAD [ファイルのパス]
でキャンセルし、続け様にgit checkout [ファイルのパス]
でファイルを復活することができます 。
$ git rm hello.txt rm 'hello.txt' $ git status On branch master Your branch is up-to-date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) deleted: hello.txt
git reset
するとインデックス上から削除したという記録を消去します。この時点ではまだファイルは削除されたままですので、git checkout
でファイルを所定の場所に再配置します。
$ git reset HEAD hello.txt Unstaged changes after reset: D hello.txt $ git checkout hello.txt
$ git reset foo.txt
git reset [ファイルのパス]
でキャンセルすることができます。
$ git add foo.txt $ git status On branch master Your branch is up-to-date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: foo.txt
git reset
するとUntracked fileとなり、git add
する前の状態に戻りました。
$ git reset foo.txt $ git status On branch master Your branch is up-to-date with 'origin/master'. Untracked files: (use "git add <file>..." to include in what will be committed) foo.txt
なお、git reset [ファイルのパス]
は git reset HEAD [ファイルのパス]
と同じ意味になります。