OK, after a couple escape backslashes and adding hexadecimal color support (I'd forgotten colors can go up to FF and not 99) I got the code.
Here's the updated example, and below is the code for just colors:
$string = preg_replace('#\[colou?r=([a-zA-Z]*|\#[0-9a-fA-F]*)\](.*?)\[/colou?r\]#', "<span style=\"color: $1\">$2</font>", $string); #font colour tag
I also allowed both color and coloUr, for the british.
Right, now a 4 hour hike...
Offline
Ok, we should just make a scratchers forum at this rate
Offline
This is really good and exciting! :3
Offline
Great, this is coming along nicely, what I need is a way to grab an image link, work out the width of an image and scale the image down so it does not overflow the comment boundries... I know how to measure the width and shrink it but not how to pull it from the comment...
Offline
sparks wrote:
Great, this is coming along nicely, what I need is a way to grab an image link, work out the width of an image and scale the image down so it does not overflow the comment boundries... I know how to measure the width and shrink it but not how to pull it from the comment...
Easy! Just do some CSS styling. New image replace code:
$string = preg_replace('#\[img\]([^\[]*?)\[/img\]#', "<img src=\"$1\" style=\"max-width: 500px;\"/>", $string); #img tag
That will keep the image inside 500 pixels. Adjust at your liking.
By the way, when are you going to update the code in the first post?
Offline
sparks wrote:
Good idea, I shall do that now. Erm, could you post your most recent? I don't think you posted it, just a link to a working example!
Actually I did, but it's all over the place. A neat version coming up soon, with some updates
Last edited by LS97 (2011-08-22 06:00:16)
Offline
Where did mine go?
Also, [quote] doesn't work.
Offline
Hardmath123 wrote:
Where did mine go?
Also, [quote] doesn't work.
No, duh
It's not in the code.
Offline
Great, I'm in the middle of preparing my own commenting system to take the bbcode system and I'm thinking a neat little addon would be a "contains bbcode?" function as it would allow me to better moderate my site.
What I did with my commenting system which may sound obvious, idk, but works really well is put the commenting box and displayed posts on a single page and php include() it wherever it's needed which means it does not need to be updated everywhere it's used, just once! Then each page simple needs the code
<?php $commentName = 'id for this comment'; include("commentspace.php"); ?>
and then it's there!
Offline
Hardmath, yours is amazing, but it's better suited to live displaying of bbcode to HTML - it wasn't working very well in terms of pulling the html and inserting it anywhere It's very impressive, LS97's is simple better suited to this particular application
[offtopic]Is it me or is the advanced topic forum the least moderated of the lot? There are very few moderator posts and I can't count the number of times people have shared emails in posts without them being removed... I guess its because this forum is a relatively responsible one so what little does need moderating is reported anyway...
Last edited by sparks (2011-08-22 06:14:50)
Offline
Ah, but I thought PHP could handle that. Can't you get the contents of a <div> element with it? If you can, the problem should be solved.
Offline
Hardmath123 wrote:
Ah, but I thought PHP could handle that. Can't you get the contents of a <div> element with it? If you can, the problem should be solved.
It was possible but it was a very inneficient way to do it, adding a hidden div and pulling the content wasn't working without a lot of code to do it...
Offline
I put the code together finally, and also added quote boxes
<!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>BBCode Comment Example</title> </head> <body> <?php if(isset($_POST['submit'])){ $string = $_POST['comment']; $string = str_replace("<","<",$string); #'damage' all <'s, removing html and simply displaying as text. $string = str_replace(">",">",$string); $string = str_replace(" ","<br />",$string); #line breaks $string = preg_replace('#\[img\]([^\[]*?)\[/img\]#', "<img src=\"$1\" style=\"max-width: 500;\"/>", $string); #img tag $string = preg_replace('#\[url\]([^\[]*?)\[/url\]#', "<a href=\"$1\">$1</a>", $string); #simple url tag $string = preg_replace('#\[url=([^\[]+?)\](.*?)\[/url\]#', "<a href=\"$1\">$2</a>", $string); #complex url tag $string = preg_replace('#\[quote\]([^\[]*?)\[/quote\]#', "<table width=\"90%\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\"><tr border=\"1\" style=\"background-color:#EEE; border-color: #888;\"><td>$1</td></tr></table>", $string); #simple quote tag $string = preg_replace('#\[quote=([^\[]+?)\](.*?)\[/quote\]#', "<table width=\"90%\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\"><tr border=\"1\" style=\"background-color:#EEE; border-color: #888; border-width: 1px;\"><td><strong>$1 wrote:</strong><br />$2</td></tr></table>", $string); #complex quote tag $string = preg_replace('#\[colou?r=([a-zA-Z]*|\#[0-9a-fA-F]*)\](.*?)\[/colou?r\]#', "<span style=\"color: $1\">$2</font>", $string); #font colour tag $string = preg_replace('#\[b\](.*?)\[/b\]#ms', "<strong>$1</strong>", $string); #bold $string = preg_replace('#\[i\](.*?)\[/i\]#ms', "<em>$1</em>", $string); #italics $string = preg_replace('#\[u\](.*?)\[/u\]#ms', "<span style=\"text-decoration: underline\">$1</span>", $string); #underline echo "<table width=\"500\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\"><tr>"; echo "<td border=\"2\" width=\"500px\" style=\"background-color:#FFA; border-color: #333;\">"; echo $string; echo "</td></tr></table> <br />"; } ?> <form name = 'comment' action = '<?php echo $_SERVER['REQUEST_URI'] ?>' method = 'post'> <textarea name = 'comment' rows = '10' cols = '50'><?php if(isset($string)){ echo $_POST['comment']; }?></textarea> <br /> <input type = 'submit' name = 'submit' value = 'comment'> </form> </body> </html>
This is the exact code that's present on the example page
Offline
Little problem: quote boxes glitch when used more than once inside each other.
Last edited by LS97 (2011-08-22 06:22:58)
Offline
sparks wrote:
Alright, first post updated!
In my commenting system I was planning to provide uneditable quoting to stop people misquoting - is that a good idea or not?
You mean like [quote=#502056]or something? I don't know... that also means that you can't edit out a long post or something.
Offline
LS97 wrote:
sparks wrote:
Alright, first post updated!
In my commenting system I was planning to provide uneditable quoting to stop people misquoting - is that a good idea or not?You mean like [quote=#502056]or something? I don't know... that also means that you can't edit out a long post or something.
That's true, I may use my newfound javascript knowledge to simple have the same quoting style as here...
Added the system to my commenting! here. Newlines still don't work....
Offline
Glitches I found with this code:
Let's [i]see[/i], does this [b]work[/b]? [url]wiki.scratch.mit.edu[/url] [b][url=wiki.scratch.mit.edu]AWESOMEST WIKI I KNOW[/url]!!![/b]
It put a \ before the apostrophe, it linked to http://accidentalgames.com/wiki.scratch.mit.edu rather than checking if it has a supported protocol, and if not, add the HTTP one.
Offline
I think the reason the forum is so lowly modded, is they trust everyone here, and they know that we would just report posts, plus the newscratchers just don't post here. Also spammers are going to post in the most popular forum (misc)
Offline
sparks wrote:
Okay, thanks sci.
I think your image size limiter does not work btw, LS97
Could be. I never actually tested that code. And sparks, just to point out a couple flaws on accidentalgames:
on http://www.accidentalgames.com/register.php you wrote at the bottom of the page that "* these details are not displayed on the website. None of the details you have given will be passed on or sold to any third-parties." but passwords don't have asterisks
on http://www.accidentalgames.com/termsAndConditions.php you should add 'your' to the definitions on the first line, since it's used further down.
Otherwise the site's amazing. I'd never actually seen it before!
Offline
Thanks LS97, on our Privacy policy page the password is marked as something not passed on but you're right, it should be *'d on the register page.
I'm glad you like the site though! It took a lot of work
Offline