BillyBoB Posted June 1, 2008 Share Posted June 1, 2008 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. Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted June 1, 2008 Author Share Posted June 1, 2008 I solved this on my own I just need to remove all \n from the string. Because I didn't know that regex won't do new lines. Even with the multi line thing set at the back. EX: preg_match_all('/.+/m', $string); Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted June 1, 2008 Share Posted June 1, 2008 I solved this on my own I just need to remove all \n from the string. Because I didn't know that regex won't do new lines. Even with the multi line thing set at the back. EX: preg_match_all('/.+/m', $string); use s instead of m Quote Link to comment 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.