<?xml version="1.0" encoding="utf-8"?>
<!-- generator="FeedCreator 1.7.2-ppt DokuWiki" -->
<?xml-stylesheet href="https://tm.root-n.com/lib/exe/css.php?s=feed" type="text/css"?>
<rss version="2.0">
    <channel>
        <title>Tipsというかメモ programming:php:cli</title>
        <description></description>
        <link>https://tm.root-n.com/</link>
        <lastBuildDate>Tue, 18 Nov 2025 19:35:32 +0900</lastBuildDate>
        <generator>FeedCreator 1.7.2-ppt DokuWiki</generator>
        <image>
            <url>https://tm.root-n.com/lib/images/favicon.ico</url>
            <title>Tipsというかメモ</title>
            <link>https://tm.root-n.com/</link>
        </image>
        <item>
            <title>PHP :: CLI / 文字コード変換を行うワンライナー</title>
            <link>https://tm.root-n.com/programming:php:cli:conv_encoding</link>
            <description>UTF-8 から SJIS に変換
   
%some_command | php -r 'while($stdin=fgets(STDIN,4096)) echo mb_convert_encoding($stdin, &quot;SJIS&quot;, &quot;UTF-8&quot;);'
   






UTF8 で 保存されたテキスト「utf8.txt」の内容



あいうえお


less コマンドで開く(端末の出力設定は SJIS)</description>
        <category>programming:php:cli</category>
            <pubDate>Sun, 16 Mar 2008 22:48:11 +0900</pubDate>
        </item>
        <item>
            <title>PHP :: BOM検出スクリプト</title>
            <link>https://tm.root-n.com/programming:php:cli:detect_bom</link>
            <description>/path/to/dir 配下で BOM(Bite Order Mark) が含まれるファイルを検出するスクリプト


% cd /path/to/dir
% for f in `find . -type f`
php -r '$hex = bin2hex(file_get_contents(&quot;$argv[1]&quot;)); if(strpos($hex, &quot;efbbbf&quot;)===0) echo $argv[1].&quot;\n&quot;;' -- $f</description>
        <category>programming:php:cli</category>
            <pubDate>Tue, 14 Oct 2008 12:03:27 +0900</pubDate>
        </item>
        <item>
            <title>PHP :: CLI / 対話的なインターフェイスの例</title>
            <link>https://tm.root-n.com/programming:php:cli:interactive</link>
            <description>下記のスクリプトを「interactive.php」として保存。


#!/usr/local/bin/php -q
&lt;?php

$name   = &quot;hoge&quot;;
$passwd = &quot;1234&quot;;

set_time_limit(0);
$stdin = fopen(&quot;php://stdin&quot;, &quot;r&quot;);

// fopen に失敗した場合、これを記述しておかないと下の while で無限ループが発生する。
if ( ! $stdin) {
    exit(&quot;[error] STDIN failure.\n&quot;);
}

while (true) {
    $input_name   = '';
    $input_passwd = '';

    echo &quot;Input your name: &quot;;
    $input_name = trim(fgets($stdin, 64));

    if ($input_name == '') continue;

    echo &quot;Input ${input_name}'s password: &quot;;
    $input_…</description>
        <category>programming:php:cli</category>
            <pubDate>Sun, 16 Mar 2008 22:48:11 +0900</pubDate>
        </item>
        <item>
            <title>PHP :: CLI / マルチバイト変換プログラム(mbConvertEncoding.php)</title>
            <link>https://tm.root-n.com/programming:php:cli:mbconvertencoding</link>
            <description>標準入力(STDIN)からファイルやストリームを読み込んで、文字コード変換して標準出力(STDOUT)に出力するプログラム。

nkf コマンドは同様の機能があり、もっと高機能ですが、nkf コマンドを入れるまでもない時や入れることができない時に使えます。

もちろん CLI版のphpがインストールされていることが前提ですが。

なお、Cygwin を含め、Windows上では動作しません。</description>
        <category>programming:php:cli</category>
            <pubDate>Fri, 20 Mar 2009 19:15:57 +0900</pubDate>
        </item>
    </channel>
</rss>
