2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

この記事誰得? 私しか得しないニッチな技術で記事投稿!

PHPのvar_dumpをconsole.logに出力する

Last updated at Posted at 2023-06-28

はじめに

PHPのvar_dumpの結果をconsole.logに出力する備忘録です。
console.table等への変換は各自でお願いします。
なお、元々エラーウィンドウを表示させる場面で作成したので、echoが汚れるのは悪しからず。

流し見たんですが、全く同じ投稿は無かったようなので投稿。
もし先駆者様いらっしゃったら誠にごめんなさい。


ソース

php
$ary = array(
    'key' => 'value',
);

ob_start();
var_dump($ary);
$out = ob_get_clean();
$out = str_replace(PHP_EOL, '\n', $out);

$out = htmlspecialchars($out);
//$out = str_replace('"', '\"', $out);
//特殊文字がなさそうならダブルクォートのみの変換でもいい

echo "<script type=\"text/javascript\">console.log(\"{$out}\");</script>";

履歴

2023/06/28 初稿

2
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?