PHPのhighlight_string()関数
例
PHP構文が強調表示された文字列を出力します。
<html>
<body>
<?php
highlight_string("Hello world! <?php phpinfo(); ?>");
?>
</body>
</html>
上記のコードのブラウザ出力は次のようになります。
Hello world! <?php phpinfo(); ?>
上記のコードのHTML出力は(ソースの表示)になります。
<html>
<body>
<code>
<span style="color: #000000">Hello world!
<span style="color: #0000BB"><?php phpinfo</span>
<span style="color: #007700">(); </span>
<span style="color: #0000BB">?></span>
</span>
</code>
</body>
</html>
定義と使用法
Highlight_string()関数は、PHP構文が強調表示された文字列を出力します。文字列は、HTMLタグを使用して強調表示されます。
構文の強調表示に使用される色は、php.iniファイルまたはini_set()関数で設定できます。
構文
highlight_string(string,return)
パラメータ値
Parameter | Description |
---|---|
string | Required. Specifies the string to be highlighted |
return | Optional. If set to TRUE, this function will return the highlighted code as a string, instead of printing it out. Default is FALSE |
技術的な詳細
戻り値: | 成功した場合はTRUEを返し、失敗した場合はFALSEを返します |
---|---|
PHPバージョン: | 4歳以上 |
変更ログ: | リターンパラメータはPHP4.2.0で追加されました |
❮PHPその他のリファレンス