Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6
This is the forum to discuss the Wrox book Beginning PHP, Apache, MySQLWeb Development by Michael K. Glass, Yann Le Scouarnec, Elizabeth Naramore, Gary Mailer, Jeremy Stolz, Jason Gerner; ISBN: 9780764557446
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 14th, 2004, 10:55 AM
Authorized User
 
Join Date: Jul 2004
Location: , , .
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default A new chapter 15 problem with BBcodes

I've discovered this problem after I made a fix for the compatability problems I had using the forum on mySQL version 3.23.58. Read my posting (Chapter 15 problems) a few days ago.

This problem is with the bbcode function in functions.php
Again! This was a compatability problem, but this time it's PHP. I'm running PHP 4.1.2 and html_entity_decode() is a PHP 4.3 function.

Well I've tried to build a fix for it using:

function unhtmlentities($string)
{
   $trans_tbl = get_html_translation_table(HTML_ENTITIES);
   $trans_tbl = array_flip($trans_tbl);
   return strtr($string, $trans_tbl);
}

function bbcode($data) {

...

      $bbcode['tpl'][] =
        "§" . unhtmlentities($row['template'],ENT_QUOTES). "§i";
      $bbcode['rep'][] =
        unhtmlentities($row['replacement'],ENT_QUOTES);
    }

...

Here's my complete code:

function unhtmlentities($string)
{
   $trans_tbl = get_html_translation_table(HTML_ENTITIES);
   $trans_tbl = array_flip($trans_tbl);
   return strtr($string, $trans_tbl);
}

function bbcode($data) {
  $sql = "SELECT * FROM forum_bbcode";
  $result = mysql_query($sql);
  if (mysql_num_rows($result) > 0) {
    while($row = mysql_fetch_array($result)) {
      $bbcode['tpl'][] =
        "§" . unhtmlentities($row['template'],ENT_QUOTES). "§i";
      $bbcode['rep'][] =
        unhtmlentities($row['replacement'],ENT_QUOTES);
    }
    $data1 = preg_replace($bbcode['tpl'],$bbcode['rep'],$data);
    $count = 1;
    while (($data1 != $data) and ($count < 4)) {
      $count++;
      $data = $data1;
      $data1 = preg_replace($bbcode['tpl'],$bbcode['rep'],$data);
    }
  }

  return $data;
}

And here's the original function:

function bbcode($data) {
  $sql = "SELECT * FROM forum_bbcode";
  $result = mysql_query($sql);
  if (mysql_num_rows($result) > 0) {
    while($row = mysql_fetch_array($result)) {
      $bbcode['tpl'][] =
        "§" . html_entity_decode($row['template'],ENT_QUOTES). "§i";
      $bbcode['rep'][] =
        html_entity_decode($row['replacement'],ENT_QUOTES);
    }
    $data1 = preg_replace($bbcode['tpl'],$bbcode['rep'],$data);
    $count = 1;
    while (($data1 != $data) and ($count < 4)) {
      $count++;
      $data = $data1;
      $data1 = preg_replace($bbcode['tpl'],$bbcode['rep'],$data);
    }
  }

  return $data;
}

Now here's my problem:
I'm getting this error on each thread's sub thread:

Warning: Compilation failed: missing terminating ] for character class at offset 22 in /removed/forum/functions.php on line 355

Can anyone explain why I would have a missing (])

PS. I don't know why the original has (ÂÂ) but that's not my problem!

Reply With Quote
  #2 (permalink)  
Old August 14th, 2004, 01:24 PM
Authorized User
 
Join Date: Jul 2004
Location: , , .
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've managed to solve the problem I mentioned earlier!

The problem wasn't with the script I wrote. The script works fine!

What I'd done was to systematically replace all the single quotes in admin.php (and all the pages) with escaped double quotes (\"). Well! doing this in the form values meant that the wrong characters were being escaped.

So I corrected my code to be:

          "<input class=\"mono\" type=\"text\" name=\"bbcode_t". $k . "\" " .
          "value='" . $v['template'] . "' size=\"32\">" .
          "</td>\n<td>" .
          "<input class=\"mono\" type=\"text\" name=\"bbcode_r". $k . "\" " .
          "value='" . $v['replacement'] . "' size=\"32\">" .

Everything now works fine!

Reply With Quote
  #3 (permalink)  
Old September 11th, 2004, 11:11 PM
Registered User
 
Join Date: Sep 2004
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Phil, thank you so much for posting this and your other chapter 15 fixes.

I am running PHP 4.3.8 and MySQL 3.23.56 and so I had the obvious problems from not having MySQL 4. And I also had the problem mentioned in this thread, but your first post fixed it.

Thanks so much!!! ;)


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
chapter 15 problem golfbird BOOK: Beginning Visual C++ 6 7 September 9th, 2008 12:29 PM
Chapter 16 BBCodes phlop BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 2 June 12th, 2008 04:24 AM
Chapter 15 problem PhilM BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 16 March 10th, 2008 02:46 PM
Chapter 15 Problem rsearing BOOK: Beginning ASP.NET 2.0 and Databases 3 October 12th, 2006 02:59 PM
Chapter 15 Search Problem PhilM BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 2 November 2nd, 2004 05:08 PM



All times are GMT -4. The time now is 01:52 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.