Current location: Hot Scripts Forums » Programming Languages » PHP » BB Code Parser and PHP 5 Problem


BB Code Parser and PHP 5 Problem

Reply
  #1 (permalink)  
Old 05-10-05, 10:22 PM
ozwald ozwald is offline
Newbie Coder
 
Join Date: Apr 2005
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
BB Code Parser and PHP 5 Problem

I've got a simple BB code to HTML parser that I'm using. Here's the code for that:

PHP Code:

function bb2html($text) {

  
$bbcode = array("<"">",
    
"[list]""[*]""[/list]"
    
"[img]""[/img]"
    
"[b]""[/b]"
    
"[u]""[/u]"
    
"[i]""[/i]",
    
'[color="'"[/color]",
    
"[size=\"""[/size]",
    
'[url="'"[/url]",
    
"[code]""[/code]",
  
'"]');
  
$htmlcode = array("&lt;""&gt;",
    
"<ul>""<li>""</ul>"
    
"<img src=""</img>"
    
"<b>""</b>"
    
"<u>""</u>"
    
"<i>""</i>",
    
'<font color="'"</font>",
    
"<span style=\"font-size:""</span>",
    
'<a href="'"</a>",
    
"<code>""</code>",
  
'">');
  
$newtext str_replace($bbcode$htmlcode$text);
  return 
$newtext;

It works perfectly fine with PHP 4.3.9, but when used with PHP 5, the font color, font size, image, and url conversions get messed up. For example, here is what a url that gets inserted into the database after being parsed looks like:

[CODE]
[url=\"http://www.google.com\">Google</a>
[/CODE]

Does anyone know how I can fix this? Thanks.
Reply With Quote
  #2 (permalink)  
Old 05-12-05, 01:24 AM
kenetix kenetix is offline
Newbie Coder
 
Join Date: Feb 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by ozwald
I've got a simple BB code to HTML parser that I'm using. Here's the code for that:

PHP Code:

function bb2html($text) {

  
$bbcode = array("<"">",
    
"[list]""[*]""[/list]"
    
"[img]""[/img]"
    
"[b]""[/b]"
    
"[u]""[/u]"
    
"[i]""[/i]",
    
'[color="'"[/color]",
    
"[size=\"""[/size]",
    
'[url="'"[/url]",
    
"[code]""[/code]",
  
'"]');
  
$htmlcode = array("&lt;""&gt;",
    
"<ul>""<li>""</ul>"
    
"<img src=""</img>"
    
"<b>""</b>"
    
"<u>""</u>"
    
"<i>""</i>",
    
'<font color="'"</font>",
    
"<span style=\"font-size:""</span>",
    
'<a href="'"</a>",
    
"<code>""</code>",
  
'">');
  
$newtext str_replace($bbcode$htmlcode$text);
  return 
$newtext;

It works perfectly fine with PHP 4.3.9, but when used with PHP 5, the font color, font size, image, and url conversions get messed up. For example, here is what a url that gets inserted into the database after being parsed looks like:

[CODE]
[url=\"http://www.google.com\">Google</a>
[/CODE]

Does anyone know how I can fix this? Thanks.
you are simply using the str_replace function, that simply replaces a string with another string. It worked in php 4 because php4 is probably more lenient with code parsings.

Example:
you are replacing <a href=" with [url="
not only are you not replacing the closing brace (>), it will not work if the person keyed in <a **** href=" , where **** represents spaces.
__________________
http://KENETIX.NET - FREE MONEY MAKING TOOLS & RESOURCES
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML spider/bot parser, and insert into DB? davidsetagaya PHP 3 05-12-05 04:28 PM
PHP parser error rocky PHP 1 08-21-04 05:08 AM


All times are GMT -5. The time now is 06:44 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.