Download the PHP package nyratas/php-console-log without Composer
On this page you can find all versions of the php package nyratas/php-console-log. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nyratas/php-console-log
More information about nyratas/php-console-log
Files in nyratas/php-console-log
Package php-console-log
Short Description Displays var_dump()s in the browser's JavaScript console.
License MIT
Homepage https://github.com/Nyratas/php-console-log
Informations about the package php-console-log
PHP console.log()
PHP console.log() allows you to dump PHP variables in the browser's console. It is an easy-to-use and lightweight PHP library.
Installation
With Composer
Manually
Just download/clone this repository and require
the autoload file:
Usage
More detailed working examples can be found in the ./examples/
directory.
Don't forget to use
the library's facade:
Basic PHP console.log()
Define a place where the library should output the console logs:
You can now use the Console::log()
method everywhere, as long as it is called before a Console::exec()
call.
You can use Console::log()
with any type of variable. If you want to output an PHP array or object, the library will show a JavaScript Array or Object in the browser's console. A boolean will remain a boolean, an integer will remain an integer, a string remain a string, and so on.
Edit the <script>
tag
All this library does is generating a <script>
-tag at the location of the Console::exec()
call.
This tag contains the required JavaScript logic in order to output the requested data in the browser's console. There is not much you can do on the generated JavaScript code, but you could want to add an attribute on the <script>
tag.
The library generates the following default HTML markup:
You can remove or modify the data-php-console-log
attribute by setting it as follows:
Wordpress tip
Do you want to use this library on a wordpress theme ? Just add the following line in your functions.php
file and start Console::log()
-ing right now !
What now ?
Well, I wrote this library in a hurry, so there's probably a lot to change/add. Feel free to contribute or to request some changes.
Enjoy!