All pastes #106825 Raw Edit

zCode parser

public php v1 · immutable
#106825 ·published 2006-07-30 16:38 UTC
rendered paste body
	function parse_code($matches) {		$types = array('html' => 'HTML', 'xhtml' => 'HTML', 'css' => 'CSS', 'javascript' => 'JavaScript',			'xml' => 'XML', 'php' => 'PHP', 'sql' => 'SQL', 'asp' => 'ASP',			'smarty'=> 'Smarty', 'apache' => 'Apache', 'perl' => 'Perl',			'actionscript' => 'ActionScript', 'c' => 'C', 'cpp' => 'C++',			'csharp' => 'C#', 'd' => 'D', 'java' => 'Java', 'python' => 'Python',			'pascal' => 'Pascal', 'delphi' => 'Delphi', 'vb' => 'VB',			'vbnet' => 'VB .Net', 'qbasic' => 'QBasic', 'asm' => 'Asm',			'darkbasic' => 'DarkBasic', 'ocaml' => 'Ocaml', 'ada' => 'Ada',			'mpasm' => 'Mpasm', 'nsis' => 'Nsis', 'visualfoxpro' => 'Visual FoxPro',			'objc' => 'Objc', 'matlab' => 'MatLab', 'diff' => 'Diff',			'oobas' => 'Oobas', 'oracle8' => 'Oracle8', 'vhdl' => 'Chdl',			'caddcl' => 'Caddcl', 'cadlisp' => 'Cadlisp', 'c_mac' => 'C_mac',			'lisp' => 'Lisp', 'bash' => 'Bash', 'lua' => 'Lua', 'zcode' => 'Zcode',			'' => 'Autre', 'console' => 'Console'		);				if (!array_key_exists($matches[1], $types)) {			$matches[1] = '';		}				$matches[2] = html_entity_decode($matches[2]);						$type = $types[$matches[1]];		require_once('./parser/geshi.php');				$geshi = new GeSHi($matches[2], 'HTML');		$new_str = $geshi->parse_code();		$new_str = '<span class="code">Code '. $matches[1] .'</span><div class="code2 '. $matches[1] .'">'. $new_str .'</div>';		return $new_str;	}		$source = preg_replace_callback('`&lt;code\s*type="(.+)"&gt;(.+)&lt;/code&gt;`imsU', 'parse_code', $source);		function parse_list($matches) {		$new_str = preg_replace('`(\r\n|\r|\n)*(&lt;puce&gt;.+&lt;/puce&gt;)(\r\n|\r|\n)*`imsU', '$2', $matches[3]);			if(preg_match('`&lt;liste\s*(type="(.?)")?&gt;((?:.(?!&lt;liste&gt;))*)&lt;/liste&gt;`imsU', $matches[3]) != 0) {			$new_str = preg_replace_callback('`&lt;liste\s*(type="(.?)")?&gt;((?:.(?!&lt;liste&gt;))*)&lt;/liste&gt;`imsU', 'parse_list', $new_str);		}			$new_str = preg_replace('`&lt;puce&gt;(.+)&lt;/puce&gt;`imsU', '<li>$1</li>', $new_str);			if(isset($matches[1]) && $matches[1] != '') {			$new_str = '<ol class="ol_'. $matches[2] .'">'. $new_str .'</ol>';		} else {			$new_str = '<ul>'. $new_str .'</ul>';		}		return $new_str;	}	$source = preg_replace_callback('`&lt;liste\s*(type="(.?)")?&gt;((?:.(?!&lt;liste&gt;))*)&lt;/liste&gt;`imsU', 'parse_list', $source);	$source = preg_replace_callback('`&lt;liste\s*(type="(.?)")?&gt;(.+)&lt;/liste&gt;`imsU', 'parse_list', $source);