Combing Preg_Replace for BBcode

Hi All,

I’m making some BBcode for a textarea. I want to create a mouseover function (french to english) when the form is submitted if a word is marked with BBcode. I think this may be possible by combining ‘preg_replace commands’. But, I have no idea how to do this - or if it is possible.

here is my php code - obviously the html code needs to be combined:

//[E=english]english[/E]
	$passage = preg_replace('/\\[E](.+?)\\[\\/E]/i',
		'<...onMouseover="showtip('"$1"');onMouseout="hidetip()">', $passage);
		
	
	
  // [F=Frenchl]French Word[/F]
  $3 = '#';
  $passage = preg_replace('/\\[Ur](.+?)\\[\\/Ur]/i',
  	  '<a href="$3">$1</a>', $passage);

Any help is appreciated.

I’ve made it close but can’t seem to combine the code. The <a /> keeps locking out the additional html.

$passage = preg_replace('/\\[F](.+?)\\[\\/F]/i',
  	  '<a href="#">$1</a>', $passage);
  	  
  	  //[E=english]english[/E]
	$passage = preg_replace('/\\[E](.+?)\\[\\/E]/i',
		'onMouseover="showtip("$1");onMouseout="hidetip()"', $passage);

This generates:

<a href="#"> F$1 </a>onMouseover="showtip(" E$1");onMouseout="hidetip()"

I need to get the “onMouseover…” into the brackets.

Hi All,

Figured it out –

//[URL=]  put mouseover in html for a href
	$passage = preg_replace (
		'/\\[URL=(.+?)]([^[]+)\\[\\/URL]/i',
		'<a href="#" onMouseover="showtip("$1")"; onMouseout="hidetip()">$2</a>', $passage);

Generates the correct code:

<a href="#" onMouseover="showtip("E$1")"; onMouseout="hidetip()"> F$2</a>

Hoepfully useful to other folks

Hi All,

I’m even closer but still need some help. Note the adjustments below.

// text is same as link
	$passage = preg_replace (
		'/\\ ([ -a-z0-9._~:\\/?#@!$&\\'()*+,;=%]+)\\[\\/URL]/i',
		'<a href="$1">$1</a>', $passage);

	//  text is different from link
	$passage = preg_replace (
		'/\\[URL=([ -a-z0-9._~:\\/?#@!$&\\'()*+,;=%]+)]([^[]+)\\[\\/URL]/i',
		'<a href="#" onMouseover="showtip("$1")"; onMouseout="hidetip()">$2</a>', $passage);

This gives me the html - notice all my html code has been ignored:

<a href="F$1"> $2</a>

Please help! Thanks.
I’m following Kevin’s book on BBcode and hyperlinks.