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

Reply via email to