Jump to content

RegExx or BBCodes??


gaza165

Recommended Posts

I am currently using BBCodes to do the code tag in my blog, I need a regular expression to search for php code and to change their colors acccordingly.

 

Just like PHP Freaks does....

 

variables are a color

functions are a colour.

 

Just like below, thats what i want to accomplish...

 

<?php

$string = str_replace($string,"Hello","Hello there..."
echo $string

?>

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/130257-regexx-or-bbcodes/
Share on other sites

Can somone please help me!!!!

 

I need a way to search for PHP code in my blog posts and to match the colors to fit with the code.

 

Just like phpfreaks does, hope someone can help me with this. Have been tearing my hair out over this.

 

Thanks

 

Garry

Link to comment
https://forums.phpfreaks.com/topic/130257-regexx-or-bbcodes/#findComment-675504
Share on other sites

I'd do something like this:

 

<?php

$code = <<<CODE
  some content
  goes here
<?php

morePHPcode();

while ( !($succeed = try()) );

echo 'foo'.\$bar;

?>
here's some <b>more</b> content, ect. ect.
CODE;

echo hiliteCode( $code );

function hiliteCode( $input ) {

$regex = '/<\?.*?\?>/s';
return preg_replace_callback(
	$regex,
	create_function(
		'$m',
		'return "<pre>".highlight_string( $m[0], TRUE )."</pre>";'
	),
	$input
);

}

?>

Link to comment
https://forums.phpfreaks.com/topic/130257-regexx-or-bbcodes/#findComment-675603
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.