Jump to content

BBcode [color]


smiles
 Share

Recommended Posts

Hi ! I have a problem with BBcode like thisHere is I am using

$patterns[] = '@\[color=(.*)\](.*)\[/color\]@'; // Matches [color=COLOR]TEXT[/color]$replaces[] = '<font color="$1">$2</font>';

Now it only right when I type

 [color=blue]test[/color]

Not true for all the rest case like:1.

[color=blue]test[/color]

2.

[color=blue]test[/color]

...Could you show me the way to solve it !Thanks :)

Link to comment
Share on other sites

Hi ! I use regex for url so when you type http://..... in your post, it auto change to url instead using [code]&#91;url&#93;http&#58;//........&#91;/url&#93;[/code]but i also allow people to embed code for video, audio using embed tag, it also has url (for video, audio) and it creates confliction :) How can I fix it ? (regex continue ?)Thanks !!!
Link to comment
Share on other sites

Hi ! Like this, I am using URL match regex so people don't need to use

[url]link here[/url]

But suppose in the post, they also post the video embed code like this

<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/cRAMkZxqudg"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/cRAMkZxqudg" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>

When they click Submit, the post will be checked for URL pattern, the problem starts because it also check URL match in the embed code and replace them as a link ?How can I solve it :)

Link to comment
Share on other sites

Thanks justsomeguy !!!I got your idea and maybe here is the last, anyway it works well to me now :)

$patterns[] = '@((\s|\\\n)((www|http)(\W+\S+[^).,:;?\]\} \r\n$]+)))@'; $replaces[] = ' <a href="$3" target="_blank">$3</a> ';$a_answer = preg_replace($patterns, $replaces, $a_answer);

Link to comment
Share on other sites

You could, but you would have to know which color to search for. So you could maybe search for "black", "white", "red", etc, but if you use a regular expression you can replace any color[/i]"] with <color="any color">, you can just replace the pattern but use the same original value.I'm sure someone will stop by to mention that <color> is not an HTML element, but that's not the point. The point is that with str_replace you can only look for a specific string, with a regular expression you can find something that matches a certain pattern (like xxx[/i]"], whatever xxx is).That being said, if you are only looking for a specific string and not necessarily a pattern, using str_replace is faster then using regular expressions. Regular expressions are powerful but the regular expression engine involves some overhead that makes it slower for replacing vs. str_replace.

Link to comment
Share on other sites

is <color> even a tag? But you would use preg_replace(or eregi_replace) like so:

 $text = $_POST['text']; $text = preg_replace("/\[color\=([\#?a-z0-9]+)\]/i","<span style=\"color:$1\">",$text); echo $text;

Should do it... at least by the example you've given.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...