Jump to content

[SOLVED] BBCode Parsing


BillyBoB

Recommended Posts

I am creating a BBCode parser it also parses emoticons (the smiley etc.).

The problem comes in when I have [ code] tags because I don't want to have emoticons in the code.

 

I have created a small regex to see if I can match all the code strings and replace them for later emplacement after parsing the emoticons.

<?php
preg_match_all("/\<p style=\"background: #BBBBBB; border: 1px solid #555555; padding: 6px;\"\>.+\<\/p\>/Ui", $selection, $matches);
?>

 

In earlier code I have replaced the [ code]* tags with the <p style=\"background: #BBBBBB; border: 1px solid #555555; padding: 6px;\"> html. This formats a small box with html and php code in it.

 

The selection I am trying to parse is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<title>BBCode Class Test</title>
	<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
</head>
<body>

		<center>
			<table>

				<tr>
					<td>
						Abc<sup>abc</sup><sub>ABC</sub>
					</td>
					<td>
						AAA
					</td>
				</tr>

				<tr>
					<td>
						<font size="28px">CCCCCCC</font>
					</td>
					<td>
						ACDB
					</td>
				</tr>
			</table>

		</center>
		aaa<b>
		<p style="background: #BBBBBB; border: 1px solid #555555; padding: 6px;"><span style="font: bold 10px Courier New;">   CODE :</span><br/><code><span style="color: #000000">
<img src="emoticons/smiley.gif" alt="Smiley" /> <span style="color: #0000BB"><?php </span><span style="color: #007700">echo(</span><span style="color: #DD0000">"hello world"</span><span style="color: #007700">); </span><span style="color: #0000BB">?></span>
</span>

</code></p>
		<p style="background: #BBBBBB; border: 1px solid #555555; padding: 6px;"><span style="font: bold 10px Courier New;">   CODE :</span><br/><code><span style="color: #000000">
<html><head></head><body></body></html></span>
</code></p>
		<a href="http://google.com">google</a>
		<a href="http://yahoo.com">http://yahoo.com</a>


		 <img src="emoticons/smiley.gif" alt="Smiley" /> <img src="emoticons/wink.gif" alt="Wink" /> <img src="emoticons/cheesy.gif" alt="Cheesy" /> <img src="emoticons/grin.gif" alt="Grin" /> <img src="emoticons/angry.gif" alt="Angry" /> <img src="emoticons/sad.gif" alt="Sad" /> <img src="emoticons/shocked.gif" alt="Shocked" /> <img src="emoticons/cool.gif" alt="Cool" /> <img src="emoticons/huh.gif" alt="Huh" /> <img src="emoticons/rolleyes.gif" alt="Roll Eyes" /> <img src="emoticons/tongue.gif" alt="Tongue" /> <img src="emoticons/embarrassed.gif" alt="Embarrassed" /> <img src="emoticons/lipssealed.gif" alt="Lips Sealed" /> <img src="emoticons/undecided.gif" alt="Undecided" /> <img src="emoticons/kiss.gif" alt="Kiss" /> <img src="emoticons/cry.gif" alt="Cry" />

		</body>
</html>

 

As you can see it has replace the emotions( : ) : D etc.) with icons which is where the word emoticon comes from. But if you look toward the top it has the words array( 0 => array()) this is the matches array that I have printed right after running the above regex.

Link to comment
Share on other sites

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.