Jump to content

Recommended Posts

Hi all, first post.

Basically, my site has bbcode style regular expressions.

However, I was wondering if there's a way to call a function on an extracted regular expression?

For example,

 

<?php
function replacewithfunction($str)
{
	$exist = '/\[code lang\=(.*?)\](.*?)\[\/code\]/is';

	$replace = geshi_code($1, $2);

	$return = preg_replace($exist, $replace, $str);
	return $return;
}
?>

 

Where geshi_code() is the function I wish to call.

Obviously this returns a syntax error, but this is basically what I want do.

Any help would be much appreciated.

Thanks,

Jack.

Hmm...had a look. I've now got this-

<?php
function geshi_code($lang, $source)
{
	include('geshi/geshi.php');
	$path = 'geshi/geshi/';

	$geshi = new GeSHi($source, $lang, $path);
	return $geshi->parse_code();
}
function str_code($str)
{
	$str = htmlspecialchars($str);
	$exist = '/\[somecode lang\=(.*?)\](.*?)\[\/somecode\]/is';

	$replace = geshi_code("$1", "$2");

	return preg_replace($exist, $replace, $str);

}

echo str_code("This is some code.[somecode lang=php]<?php $var = 'hello'; ?>[/somecode] end of code.");
?>

But it returns this-

This is some code.

 

<?php $var = 'hello'; ?>

 

end of code.

 

Unhighlighted. In case you didn't know, geshi is a syntax highlighter.

I don't understand why it's not working...

 

Thanks anyway.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.