- preg_match: documentation ( source)
<?php
class interpreter {
private $_code;
public function __construct($code) {
if(!is_string($code)) exit('Error while parsing code; Code not conformal.');
$this->_code = $code;
$this->exec();
}
public function parser($code = null) {
$array = [];
if($code === null) $code = $this->_code;
if(preg_match('#print\((.*)\)#', $code, $array)) echo($array[1]);
}
}
$code = 'print("Hello World!");';
$program = new interpreter($code);