[OT] Very basic test


log in or register to remove this ad




OK think I have figured out how this works now :)
PHP:
function doVbCode($strTemp){

	// Fix Italics, Underline and Boldface HTML formatting
	$strTemp = preg_replace( "/\[i\](.*?)\[\/i\]/s", "<i>\\1</i>", $strTemp );
	$strTemp = preg_replace( "/\[u\](.*?)\[\/u\]/s", "<u>\\1</u>", $strTemp );
	$strTemp = preg_replace( "/\[b\](.*?)\[\/b\]/s", "<b>\\1</b>", $strTemp );

	// Fix List HTML formatting
	$strTemp = preg_replace( "/\[list\](.*?)/s", "<ul>\\1", $strTemp );
	$strTemp = preg_replace( "/\[list\=(.*?)\](.*?)/s", "<ol type='\\1'>\\2", $strTemp );
	$strTemp = str_replace( "[/list]", "</ul>", $strTemp );
	$strTemp = preg_replace( "/\[\/list\=(.*?)\]/s", "</ol>", $strTemp );
	$strTemp = str_replace( "[*]", "<li>", $strTemp );

	// Fix The Quote HTML formatting
	$strTemp = preg_replace( "/\[quote\](.*?)/s", "<blockquote><font size=1>quote:</font><br><hr size=1 width=100%>\\1", $strTemp );
	$strTemp = preg_replace( "/\[quote\=(.*?)\](.*?)/s", "<blockquote><font size=1>quote: <i>Originally Written by \\1</i></font><br><hr size=1 width=100%>\\2", $strTemp );
	$strTemp = str_replace( "[/quote]", "<hr size=1 width=100%></blockquote>", $strTemp );

	// Fix Font Size HTML formatting
	$strTemp = preg_replace( "/\[size\=(.*?)\](.*?)/s", "<font size='\\1'>\\2", $strTemp );
	$strTemp = str_replace( "[/size]", "</font>", $strTemp );

	// Fix Font Color HTML formatting
	$strTemp = preg_replace( "/\[color\=(.*?)\](.*?)/s", "<font color='\\1'>\\2", $strTemp );
	$strTemp = str_replace( "[/color]", "</font>", $strTemp );

	// Fix Font Face HTML formatting
	$strTemp = preg_replace( "/\[font\=(.*?)\](.*?)/s", "<font face='\\1'>\\2", $strTemp );
	$strTemp = str_replace( "[/font]", "</font>", $strTemp );

	// Fix Image display Links HTML formatting
	$strTemp = preg_replace( "/\[img](.*?)\[\/img\]/siU", "<img src='\\1' align='default' border='0'>", $strTemp );
	$strTemp = preg_replace( "/\[img align=default](.*?)\[\/img\]/siU", "<img src='\\1' align='default' border='0'>", $strTemp );
	$strTemp = preg_replace( "/\[img align=left](.*?)\[\/img\]/siU", "<img src='\\1' align='left' border='0'>", $strTemp );
	$strTemp = preg_replace( "/\[img align=right](.*?)\[\/img\]/siU", "<img src='\\1' align='right' border='0'>", $strTemp );

	// Fix Hyperlinks HTML formatting
	$strTemp = preg_replace( "/\[url\](.*?)\[\/url\]/siU", "<a href='\\1' target='_self'>\\1</a>", $strTemp );
	$strTemp = preg_replace( "/\[url\=(.*?)\](.*?)\[\/url\]/siU", "<a href='\\1' target='_self'>\\2</a>", $strTemp );

	// Fix Mailto Links HTML formatting
	$strTemp = preg_replace( "/\[email\](.*?)\[\/email\]/siU", "<a href='mailto:\\1'>\\1</a>", $strTemp );
	$strTemp = preg_replace( "/\[email\=(.*?)\](.*?)\[\/email\]/siU", "<a href='mailto:\\1'>\\2</a>", $strTemp );

	$strTemp = ereg_replace("\r\n","<br>\n",$strTemp);

	return $strTemp;
}
 


Learning PHP here so I thought I could start with reverse-engineering VbCode :)

The correct DoVbCode() function can be found in the attached text file if anyone is interested (I didn't have access to the VbBulletin source code when I did this so most of it is based on guesswork)

Hopefully I passed the test, if the function works I have passed it :D
 

Attachments


Mr. Liquide!

this test is to hard, can we get a word bank or something like that ... even better, how about you give us the definitions?
 

Remove ads

Top