Jump to content

Regex checks for bbcode, variable empty? why aren't some variables processed


iarp

Recommended Posts

The code below... what i'm after is if someone inputs [ url=http://www.google.ca][/ url]  without anything in between opening and ending, to have the url http://www.google.ca show up in between there automatically.

 

<?php
function codeChanger($msg){

	$replace = array (
		'/(\[b\])(.*)(\[\/b\])/i',
		'/(\[i\])(.*)(\[\/i\])/i',
		'/(\[u\])(.*)(\[\/u\])/i',
		'/(\[img=)(.*?)(\])/i',
		'/(\[url=)(.*?)(\])(.*?)(\[\/url\])/i',
		'/(\[php\])(.*)(\[\/php\])/i',
		'/(\[file=)(.*?)(\])(.*?)(\[\/file\])/i'
	);
	$replacements = array (
		'<strong>$2</strong>',
		'<em>$2</em>',
		'<u>$2</u>',
		'<img src="$2"></img>',
		'<a href="$2">' . if(empty('$4')) '$4'; else '$2'; . '</a>',
		'<div class="codePHP">$2</div>',
		'<a href="/?file=$2">$4</a>',
	);

	return(preg_replace($replace, $replacements, $msg));
}

 

I've tried

<?php '<a href="$2">' . if(empty('$4')) '$4'; else '$2'; . '</a>', ?>

Followed immediatly by...

Parse error: syntax error, unexpected T_IF in /homepages/31/d204952132/htdocs/iarp/beta/main_inc/iarp-core-classes.php on line 157

 

As well:

<?php 
#this will be parsed just fine through the above function
[b]stuff here[/b]           # but if i break the line and have:

[b]
stuff here
[/b]

# the [b] doesn't get parsed[/b]

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.