iarp Posted April 6, 2009 Share Posted April 6, 2009 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] Quote Link to comment https://forums.phpfreaks.com/topic/152893-regex-checks-for-bbcode-variable-empty-why-arent-some-variables-processed/ Share on other sites More sharing options...
Maq Posted April 6, 2009 Share Posted April 6, 2009 Instead of .* use .+ and for the blank scenario, create another entry with the url bb tags blank, replaced with blank. Quote Link to comment https://forums.phpfreaks.com/topic/152893-regex-checks-for-bbcode-variable-empty-why-arent-some-variables-processed/#findComment-803016 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.