SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    Talk to the /dev/null Theiggsta's Avatar
    Join Date
    Mar 2001
    Location
    Tampa, FL
    Posts
    376
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Un-Do htmlspecialchars

    HELP!

    I have gotten the form submission to work and shove the data into the database, but it is all htmlspecialchared in there, how do I Un-Htmlspecialchar this code to look normal when its being outputted to the webpage?
    Aaron "Theiggsta" Kalin
    Pixel Martini
    Ruby and Rails Developer

  2. #2
    SitePoint Zealot New Oddity's Avatar
    Join Date
    Jun 2001
    Location
    Georgia
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:

    function removeSpecialChars(string $string0{
      
    $string ereg_replace("&""&"$string);
      
    $string ereg_replace(""""\""$string);
      
    $string ereg_replace("'""'"$string);
      
    $string ereg_replace("&lt;""<"$string);
      
    $string ereg_replace("&gt;"">"$string);
      return 
    $string;

    That should do it...
    --Odd
    "We all live in a yellow subroutine."
    "Some call it insanity; I call it inspiration!"

  3. #3
    SitePoint Zealot New Oddity's Avatar
    Join Date
    Jun 2001
    Location
    Georgia
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That first one should be:

    $string = ereg_replace("&amp;", "&", $string);
    --Odd
    "We all live in a yellow subroutine."
    "Some call it insanity; I call it inspiration!"

  4. #4
    SitePoint Zealot New Oddity's Avatar
    Join Date
    Jun 2001
    Location
    Georgia
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ARGH!!!!!!!!!!!!

    $string = ereg_replace("&#amp#;", "&", $string);


    Take out the hatches...
    --Odd
    "We all live in a yellow subroutine."
    "Some call it insanity; I call it inspiration!"

  5. #5
    Talk to the /dev/null Theiggsta's Avatar
    Join Date
    Mar 2001
    Location
    Tampa, FL
    Posts
    376
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks a bunch...

    you can always edit your posts you know
    Aaron "Theiggsta" Kalin
    Pixel Martini
    Ruby and Rails Developer

  6. #6
    SitePoint Zealot New Oddity's Avatar
    Join Date
    Jun 2001
    Location
    Georgia
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    *Pounding head on wall* Doh! Doh! Doh!
    --Odd
    "We all live in a yellow subroutine."
    "Some call it insanity; I call it inspiration!"

  7. #7
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And since you are simply replacing one for one, you should really use str_replace() instead of ereg_replace it is way faster if you don't need the added functionality of regular expressions, which in your case you don't. Also you can supply arrays to the str_replace() to handle all the replacements in one shot like so:
    PHP Code:
    $in = array("& amp;""& quot;""& #039;""&lt;""&gt;");
    $out = array("&"'"'"'""<"">");
    $str str_replace($in$out$str);
    print 
    $str
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  8. #8
    SitePoint Zealot New Oddity's Avatar
    Join Date
    Jun 2001
    Location
    Georgia
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cool, I'll remember that next time. So you can put arrays into str_replace? That is good to know.
    --Odd
    "We all live in a yellow subroutine."
    "Some call it insanity; I call it inspiration!"

  9. #9
    Talk to the /dev/null Theiggsta's Avatar
    Join Date
    Mar 2001
    Location
    Tampa, FL
    Posts
    376
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks a bunch freddy, ill go play around with it right now.
    Aaron "Theiggsta" Kalin
    Pixel Martini
    Ruby and Rails Developer


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •