PHP code example of helingfeng / php-javascript-transformer
1. Go to this page and download the library: Download helingfeng/php-javascript-transformer library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
helingfeng / php-javascript-transformer example snippets
// 包含特殊字符输出
app('js.transformer')->put(['username' => "'helingfeng"]);
# window.username = '\'helingfeng';
// 修改 namespace 输出
app('js.transformer')->setNamespace('profile')->put(['username' => 'helingfeng']);
# window.profile = window.profile || {};profile.username = 'helingfeng';
// 输出包含 script 标签
app('js.transformer')->
$transfer = new JavaScriptTransformer();
$script = $transfer->put(['username'=>'helingfeng']);
echo $script;
# output
window.username = 'helingfeng';