[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

03/14/2009 at 05:58PM PDT, ID: 24231046
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.7

Regular expressions

Asked by HarpuaFSB in Regular Expressions, PHP Scripting Language

Tags: PHP, regular expressions

I have a function that parses BBCode that I need to alter.

Right now, URLs are parsed via BBCode through one of three ways.

First:
[url]http://www.domain.com[/url]
Parsed:
<a href="http://www.domain.com" target="_new">http://www.domain.com</a>

Second:
[url=http://www.domain.com]Click me[/url]
Parsed:
<a href="http://www.domain.com" target="_new">Click me[/url]

Third:
http://www.domain.com
Parsed:
<a href="http://www.domain.com" target="_new">http://www.domain.com</a>

What I want to do is alter the parsing code so that any links that are from my site's domain do not get opened in new windows.  I'm guessing that this involves adding another three regex's and putting them in the right order in my function but I can't get it to work correctly.

The current parsing function is detailed below.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
function FormatBBCode($message) 
	{
		$simple_search = array(
				'/\[code\](.*?)\[\/code\]/is',
	      		'/\:\)/is',
	      		'/\;\)/is',
	      		'/\:\(/is',
	      		'/\:cool:/is',
	      		'/\:mad:/is',
	      		'/\:confused:/is',
	      		'/\:shock:/is',
	      		'/\:bigsmile:/is',
	      		'/\:oops:/is',
	      		'/\:roll:/is',
	      		'/\:twisted:/is',
	      		'/\:lol:/is',
	      		'/\:neutral:/is',
	      		'/\:drool:/is',
	      		'/\:ninja:/is',
			'/\:awesome:/is',
			'/\[b\](.*?)\[\/b\]/is',                                
	      		'/\[i\](.*?)\[\/i\]/is',                                
	      		'/\[u\](.*?)\[\/u\]/is',
	      		'/\[s\](.*?)\[\/s\]/is',
			//[url]http://domain.com[/url]
	      		'/\[url\](http:\/\/)?(.*?)\[\/url\]/is',
			//[url=http://domain.com]Click Me[/url]
	      		'/\[url\=(http:\/\/)?(.*?)\](.*?)\[\/url\]/is',
			'/\[img\](.*?)\[\/img\]/is', 
	      		'/\[youtube\]\s{0,10}(.*?)\s{0,10}\[\/youtube\]/is',
			'/\[ignvideo\]\s{0,10}(.*?)\s{0,10}\[\/ignvideo\]/is',
	      		'/\[spoiler\](.*?)\[\/spoiler\]/is',
	      		'/\[nsfw\](.*?)\[\/nsfw\]/is',
			// Any URLs not BBCoded
			'/\b(?<!=")(?<!">)(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]/is',
			'/\[gametrailers\]\s{0,10}(.*?)\s{0,10}\[\/gametrailers\]/is'
		);
		
		$simple_replace = array(
			'<span class="code"><em>Code: </em><code>$1</code></span>',
	      		'<img src="/_assets/img/smileys/smile.gif" alt=":)" />',
	      		'<img src="/_assets/img/smileys/wink.gif" alt=";)" />',
	      		'<img src="/_assets/img/smileys/sad.gif" alt=":(" />',
	      		'<img src="/_assets/img/smileys/cool.gif" alt=":cool:" />',
	      		'<img src="/_assets/img/smileys/mad.gif" alt=":mad:" />',
	      		'<img src="/_assets/img/smileys/confused.gif" alt=":confused:" />',
	      		'<img src="/_assets/img/smileys/shock.gif" alt=":shock:" />',
	      		'<img src="/_assets/img/smileys/bigsmile.gif" alt=":D" />',
	      		'<img src="/_assets/img/smileys/oops.gif" alt=":oops:" />',
	      		'<img src="/_assets/img/smileys/eyeroll.gif" alt=":roll:" />',
	      		'<img src="/_assets/img/smileys/twisted.gif" alt=":twisted:" />',
	      		'<img src="/_assets/img/smileys/laugh.gif" alt=":lol:" />',
	      		'<img src="/_assets/img/smileys/neutral.gif" alt=":neutral:" />',
	      		'<img src="/_assets/img/smileys/drool.gif" alt=":drool:" />',
	      		'<img src="/_assets/img/smileys/ninja.gif" alt=":ninja:" />',
			'<img src="/_assets/img/smileys/awesome.gif" alt=":awesome:" />',
			'<b>$1</b>',
	      		'<i>$1</i>',
	      		'<u>$1</u>',
	      		'<del>$1</del>',
			//[url]http://domain.com[/url]
	      		'<a href="http://$2" target="_new">http://$2</a>',
			//[url=http://domain.com]Click Me[/url]
	      		'<a href="http://$2" target="_new">$3</a>',
			'<img src="$1" alt="Image" />',
	      		'<object width="480" height="295"><param name="movie" value="http://www.youtube.com/v/$1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/$1" type="application/x-shockwave-flash" wmode="transparent" width="480" height="295"></embed></object>',
			'<embed src="http://videomedia.ign.com/ev/ev.swf" flashvars="$1" type="application/x-shockwave-flash" width="433" height="360"></embed>',
	      		'<span class="hidden"><em>Spoiler: </em><span>$1</span></span>',
			'<span class="hidden"><em>NSFW: </em><span>$1</span></span>',
			// Any URLs not BBCoded
			'<a href="\0" target="_new">\0</a>',
			'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="gtembed" width="480" height="392"><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="true" /><param name="movie" value="http://www.gametrailers.com/remote_wrap.php?mid=$1"/><param name="quality" value="high" /><embed src="http://www.gametrailers.com/remote_wrap.php?mid=$1" swLiveConnect="true" name="gtembed" align="middle" allowScriptAccess="sameDomain" allowFullScreen="true" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="433" height="360"></embed></object>'
	      	);
[+][-]03/14/09 09:04 PM, ID: 23889732

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/14/09 09:23 PM, ID: 23889762

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/14/09 09:30 PM, ID: 23889777

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/14/09 09:34 PM, ID: 23889784

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/14/09 09:37 PM, ID: 23889787

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/14/09 09:46 PM, ID: 23889808

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/14/09 10:08 PM, ID: 23889845

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/14/09 10:17 PM, ID: 23889863

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/14/09 10:20 PM, ID: 23889875

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Regular Expressions, PHP Scripting Language
Tags: PHP, regular expressions
Sign Up Now!
Solution Provided By: kevthedude
Participating Experts: 2
Solution Grade: A
 
 
[+][-]03/14/09 10:23 PM, ID: 23889880

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/14/09 10:36 PM, ID: 23889908

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/14/09 10:44 PM, ID: 23889923

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/14/09 10:53 PM, ID: 23889938

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/15/09 08:53 AM, ID: 23891822

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/15/09 09:00 AM, ID: 23891854

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-91 - Hierarchy / EE_QW_3_20080625