Jump to content


Photo

Forum


  • Please log in to reply
4 replies to this topic

#1 computerpros

computerpros
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 29 March 2006 - 12:39 AM

Hey! I am going to being building a forum system very soon. One thing though that I am wondering is how you would parse (and also add into posts) the ubbc code that the user posts......any suggestions? links? Your help would be appreciated.
-Computerpros

#2 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 29 March 2006 - 12:44 AM

Bit of java script to put the code in the text box (so its user friendly!)

store that directly in your database then when outputting content to the screen do a regular expression replacement of the tags for your html tags.
follow me on twitter @PHPsycho

#3 computerpros

computerpros
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 29 March 2006 - 12:46 AM

[!--quoteo(post=359490:date=Mar 28 2006, 05:44 PM:name=ToonMariner)--][div class=\'quotetop\']QUOTE(ToonMariner @ Mar 28 2006, 05:44 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Bit of java script to put the code in the text box (so its user friendly!)

store that directly in your database then when outputting content to the screen do a regular expression replacement of the tags for your html tags.
[/quote]
Could you explain that regular expression replacement stuff to me some more or point to a tut please?
-Computerpros


#4 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 29 March 2006 - 12:55 AM

quickie...

OK you have doen teh javascript to place stuff like BOLD,[h1]Header[/h1] into the text area adn teh the whole string has been saved in the database.

You want to replace SOME TEXT with bold tags adn same for h1

now you could do a string replace on just the '[' and the ']'
<?php
$string = "[b]some bold text[/b] at the start of teh post.";

$lookfor = array('[', ']');
$replacewith = array('<', '>');
$string = str_replace($lookfor, $replacewith, $string);
?>
or you could do similar with regular expressions...
<?php
$lookfor = array('/[b](?!\[)[/b]/','/[h1](?!\[)[/h1]/');
$replacewith = array('<b>\\1</b>', '<h1>\\1</h1>');
$strinng = preg_replace($lookfor, $replacewith, $string);
?>

It takes too long to explain regular expressions so juts go and find a good tutorial on them.....
follow me on twitter @PHPsycho

#5 computerpros

computerpros
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 29 March 2006 - 01:12 AM

[!--quoteo(post=359494:date=Mar 28 2006, 05:55 PM:name=ToonMariner)--][div class=\'quotetop\']QUOTE(ToonMariner @ Mar 28 2006, 05:55 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
quickie...

OK you have doen teh javascript to place stuff like BOLD,[h1]Header[/h1] into the text area adn teh the whole string has been saved in the database.

You want to replace SOME TEXT with bold tags adn same for h1

now you could do a string replace on just the '[' and the ']'
<?php
$string = "[b]some bold text[/b] at the start of teh post.";

$lookfor = array('[', ']');
$replacewith = array('<', '>');
$string = str_replace($lookfor, $replacewith, $string);
?>
or you could do similar with regular expressions...
<?php
$lookfor = array('/[b](?!\[)[/b]/','/[h1](?!\[)[/h1]/');
$replacewith = array('<b>\\1</b>', '<h1>\\1</h1>');
$strinng = preg_replace($lookfor, $replacewith, $string);
?>

It takes too long to explain regular expressions so juts go and find a good tutorial on them.....
[/quote]
Ok. That will do. Thank you!
-Computerpros




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users