英字については
strtolower()関数大文字から小文字に変換することができます。
strtoupper()関数小文字から大文字に変換することができます。
逆にするには、strrev()関数
または、substr()関数
サンプルコードの実行結果はこちら
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
<!doctype html> <html> <head> <meta charset="utf-8"> <title>文字列を変換してみる</title> <link rel="stylesheet" href="../style.css"> </head> <body> <?php $str = array("first","second","third"); ?> <table border="2"> <tr bgcolor="#c0c0c0"> <th>文字列</th> <th>大文字</th> <th>小文字</th> <th>逆順</th> <th>文字列抽出</th> </tr> <?php foreach( $str as $value ){ echo "<tr>"; echo "<td>" . $value . "</td>"; //大文字にして出力 echo "<td>" . strtoupper($value) . "</td>"; //小文字にして出力 echo "<td>" . strtolower($value) . "</td>"; //逆順にして出力 echo "<td>" . strrev($value) . "</td>"; //文字列の一部を抽出して出力 echo "<td>" . substr($value, 0, 2) . "</td>"; echo "</tr>"; } ?> </table> </body> </html> |
関数 | 戻り値 | 説明 |
---|---|---|
strtoupper(string $str) | string | 大文字に変換する |
strtolower(string $str) | string | 小文字に変換する |
strrev(string $str) | string | 逆順にする |
substr(string $str,interger $pos,interger $len) | string | pos位置から長さlenの文字列を抽出する |