The Straight Dope

Go Back   Straight Dope Message Board > Main > Mundane Pointless Stuff I Must Share (MPSIMS)

Reply
 
Thread Tools Display Modes
  #1  
Old 09-28-2010, 03:53 PM
Mangetout Mangetout is online now
Charter Member
 
Join Date: May 2001
Location: Kingdom of Butter
Posts: 47,661
PHP debug help (pretty please?)

My website runs on a flat-file PHP-based CMS called Fuzzylime that is unfortunately somewhat neglected by the original author (mainly because he's investing all his effort in his web design/setup company - I don't blame him for this).

I've learned a little PHP just through necessity of tweaking the operation of my site here and there - but I'm not anywhere near fluent in this particular language.

Long story short. The biggest bug I currently have to work around is that the CMS does not properly deal with HTML entities - if I type an ampersand into a content page, it gets converted to & - which is fine, but then on subsequent saves, it gets mangled to & - and so on.

I get why this is happening (because the ampersand character is itself part of the coding) - I think I more or less know which bit of code is responsible and why, but an expert diagnosis would be of enormous value, if anyone has the time.

Anyway, the function in the spotlight is this one:
Code:
function entryprep($entry) { // Prepares a line for saving 
    $entry = str_replace("Â&", "&", $entry); 
    $entry = str_replace("&lt;", "<", $entry); 
    $entry = str_replace("&gt;", ">", $entry); 
    $entry = str_replace("\$", "\\\$", $entry); 
    $entry = str_replace("&", "&amp;", $entry); 
    $entry = stripslashes($entry); 
    $entry = htmlentities($entry, ENT_NOQUOTES, "UTF-8"); 
    $entry = str_replace("&amp;amp;", "&amp;", $entry); 
    $entry = str_replace("&amp;quot;", "&quot;", $entry); 
    $entry = str_replace("&amp;lt;", "&lt;", $entry); 
    $entry = str_replace("&amp;gt;", "&gt;", $entry); 
    $entry = str_replace("\"", "&quot;", $entry); 
    $entry = str_replace("\\'", "'", $entry); 
    return $entry; 
}
Am I right in thinking that:
a) This code does stuff, then promptly undoes it again?
b) It also painstakingly does some of the same stuff that the htmlentities function already does natively?
c) At least some of the code here could be eliminated by adding false as the double_encode parameter of the htmlentities function? (my web server supports PHP 4 and 5)

How, if at all, would you modify/rewrite this function?
Reply With Quote
Advertisements  
Reply

Bookmarks

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
Forum Jump


All times are GMT -5. The time now is 02:37 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Send questions for Cecil Adams to: cecil@chicagoreader.com

Send comments about this website to: webmaster@straightdope.com

Terms of Use / Privacy Policy

Advertise on the Straight Dope!
(Your direct line to thousands of the smartest, hippest people on the planet, plus a few total dipsticks.)

Publishers - interested in subscribing to the Straight Dope?
Write to: sdsubscriptions@chicagoreader.com.

Copyright © 2013 Sun-Times Media, LLC.