acctman Posted September 28, 2008 Share Posted September 28, 2008 Hi can someone assist me with adding <?php to the code snippets below. Quick overview, I have to files parser.php and _parser.php the two files extract php coding from .tpl (template) files. My problem is the original coder only added <? and not <?php which is required by php5. Without writing the entire file can someone add || or && and the correct substr code to have <?php processed too, also would casing being a problem if it <?PHP or <?php. I've included both files as attachments in case cause you need to view more than the snippets I've provided. _parser.php file function print_out() { //get template content $f = fopen($this->template,'r'); if (!$f) return false; while (!feof($f)) { $s = chop(fgets($f,4096)); if ($s == '') continue; if (substr($s,0,5) == '<!--[' || substr($s,0,2) == '<?') { if ($nx != '') $this->templ[] = $nx; $this->templ[] = $s; $nx = ''; } else $nx .= "\n".$s; } if ($nx != '') $this->templ[] = $nx; fclose($f); //analyze content foreach ($this->templ as $key => $value) { //ordinary output if (substr($value,0,5) != '<!--[' && substr($value,0,2) != '<?') { $this->act[$key] = 'do_print'; } Eval linked to function below, I think //eval elseif (substr($value,0,2) == '<?') { $this->act[$key] = 'do_eval'; } if (substr($s,0,5) == '<!--[' || substr($s,0,2) == '<?') { if ($nx != '') $templ[$tid][++$tplzz] = $nx; $templ[$tid][++$tplzz] = $s; $nx = ''; } //no more statements, print output? if (substr($s,0,5) != '<!--[' && substr($s,0,2) != '<?') { if ($if[$tid][$ifcn[$tid]] && $s != '' && !$codestart) echo $s."\n"; if ($codestart) $code .= $s."\n"; continue; } //PHP code? if ($s == '<?') { $code = ''; while ($s != '?>' && $s !== false) { $s = templ_read($tid); if ($s != '?>') $code .= "\n".$s; } eval($code); $s = ''; } //one line PHP code? if (substr($s,0,2)=='<?' && substr($s,strlen($s)-2,2)=='?>') {$s = substr($s,2,strlen($s)-4); eval($s);$s = '';} parser.php file elseif (substr($s,0,2) == '<?') { if ($nx != '') $this->templ[] = $nx; $nx = $s; } this function appears to be tied to the 2nd code snippet I posted above, it appears to be looking for 2 characters <? # Eval function do_eval() { global $names, $en; extract($names); $ev = substr($this->s,2,-2); eval($ev); } [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/126129-need-help-changing-some-code-snippets/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.