This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
// https://www.npmjs.com/package/php-parser | |
var parser = require('php-parser'); | |
// https://www.npmjs.com/package/glob | |
var glob = require('glob'); | |
glob("**/*.php", options, function (er, files) { | |
for(var i = 0; i < files.length; i++) { | |
var file = files[i]; | |
try { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// initialize the php parser factory class | |
var engine = require('php-parser'); | |
var transpiler = require('php-transpiler'); | |
var jsCode = transpiler.generate( | |
engine.parseCode('<?php echo "Hello World";') | |
); | |
console.log(jsCode); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install php-transpiler --save |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var parser = require('php-parser'); | |
// initialize a new parser instance | |
var instance = new parser({ | |
parser: { | |
extractDoc: true, | |
suppressErrors: true | |
}, | |
ast: { | |
withPositions: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Some namespace & file description | |
*/ | |
namespace foo { | |
function bar($a, $b) { | |
return $a + $b; | |
} | |
// will print : 5 | |
echo bar(2, 3); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install php-parser --save |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('CRLF', "\r\n"); | |
class HaveToWork extends Thread { | |
protected $wait; | |
public $socket = null; | |
public function __construct() { | |
$this->wait = true; | |
$this->start(); | |
} | |
public function run() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class jPrototype { | |
protected static $prototype = array(); | |
public static function prototype() { | |
if ( !self::$prototype ) { | |
self::$prototype = new self(); | |
} | |
return self::$prototype; | |
} | |
public function __set($property, $value) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function renderTemplate($template, $data) { | |
$data_keys = array_map(function($key) { | |
return '%' . $key . '%'; | |
}, array_keys($data)); | |
$data_values = array_values($data); | |
return str_replace($data_keys, $data_values, $template); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Function: sanitize | |
* Returns a sanitized string, typically for URLs. | |
* | |
* Parameters: | |
* $string - The string to sanitize. | |
* $lowercase - Force the string to lowercase? | |
* $alnum - If set to *true*, will remove all non-alphanumeric characters. | |
*/ | |
function sanitize($string, $lowercase = true, $alnum = false) { |
NewerOlder