Jump to content

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


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]

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.