Re: Fw: [PHP] FORUM CODE

2002-09-04 Thread joshua

Kevin Stone wrote:
 $myformtxt = '[i]Hello[/i] [B]world[/B]';  // pretend this came from a form.

1. I understand what you're doing, and how. But what I don't understand 
is why? If a user is going to have to type [B]bold[/B], why not just get 
them to type bbold/b. [bold] and [italic] maybe?


2, I think regular expressions are a safer way to go. That way you don't 
end up inserting eroneous html into peoples text if an unmatched tag is 
  encountered. Square brackets will not throw a browser off track but an 
unclosed h1 or em tag could ruin a page's appearance.

i suggest using preg_replace, maybe like this:

$pair = array( 'bold' = 'strong',
'italics'   = 'em',
'heading1' = 'h1',
'heading2' = 'h2',
'heading3' = 'h3',
'heading4' = 'h4');

$pattern = array();
$replace = array();

foreach($pair as $key = $val) {
 $pattern[] = '/(\[)(' . $key . ')(\])([^]].*)(\[\/)(' . $key . 
')(\])/i';
 $replace[] = $val . '$4' . /$val;
}

$new_body= preg_replace ($pattern, $replace, $body_text);


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] FORUM CODE

2002-09-03 Thread Tony Harrison

Hi, im wondering how in popular forum software, those 'BB codes' are done in
PHP, like, [B] and stuff. I just cant figure it out.

-
[EMAIL PROTECTED]
http://www.cool-palace.com



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] FORUM CODE

2002-09-03 Thread Brian V Bonini

My guess would be a regex replace function. The latest version of Phorum has
this capability. You could grab the source form phorum.org and have a look.

 -Original Message-
 From: Tony Harrison [mailto:[EMAIL PROTECTED]]
 Sent: Tuesday, September 03, 2002 2:23 PM
 To: [EMAIL PROTECTED]
 Subject: [PHP] FORUM CODE


 Hi, im wondering how in popular forum software, those 'BB codes'
 are done in
 PHP, like, [B] and stuff. I just cant figure it out.

 -
 [EMAIL PROTECTED]
 http://www.cool-palace.com



 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Fw: [PHP] FORUM CODE

2002-09-03 Thread Kevin Stone

str_replace();
http://www.php.net/manual/en/function.str-replace.php

Here's an example how you might use str_replace() to create your own
scripting syntax..

---
$myformtxt = '[i]Hello[/i] [B]world[/B]';  // pretend this came from a form.

function parse_script($str)
{
 // The array could be stored in a separate file for easy editing.
 $mysyntax = array (
 '[i]' = 'i',
 '[/i]' = '/i',
 '[b]' = 'b',
 '[/b]' = '/b');

 // Loop through the array and replace each key with its value in the
string.
 foreach($mysyntax as $script = $html)
  {
  // Do once for lower case..
  $str = str_replace($script, $html, $str);

  // And once for upper case..
  $script = strtoupper($script);
  $str = str_replace($script, $html, $str);
  }
 return $str;
}

echo parse_script($myformtxt);
---

Kevin


- Original Message -
From: Tony Harrison [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, September 03, 2002 12:22 PM
Subject: [PHP] FORUM CODE


 Hi, im wondering how in popular forum software, those 'BB codes' are done
in
 PHP, like, [B] and stuff. I just cant figure it out.

 -
 [EMAIL PROTECTED]
 http://www.cool-palace.com



 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php