Hi guys,

I have some troubles understanding how to deal with strings that contain special characters.

Suppose that we have .html file which could contain some special characters just like ( - , | , % , " , ? , ......). I need to read the file, store it in a string, put it in a textarea, modify it and then save it using the write function.

The problem is that I get some error results when the file is containing special characters. My question is how can I deal with such string so I can make sure that no error in result will rise after saving.

thx...

    look into the addslashes() and stripslashes() functions.
    Hope this helps
    Rob

      Thx OhLordy,

      I think that addslashes() and stripslashes() functions are mainly used with databases, aren't they?

      I fix the problem by using:

      $new = eregi_replace("[?]","",$new);
      $new = eregi_replace("[\"]","",$new);
      $new = eregi_replace("[\/]","",$new);
      .
      .
      But I still get troubles when the string contains the single qoute character ('), I couldn't replace the (') by using both eregi_replace and str_replace functions. 😕

      Thx

        addslashes is used to escape pretty much anything, not necessarily just database stuff, and you use stripslashes when you want to display it again.

          You might want to look into htmlspecialchars() and htmlentities(). I believe those functions may solve your problem.

            yeah i think douceur is right, i believe htmlentities or htmlspecialchars will do the trick 🙂 but it can be a pain to get to work just right on multiple pages 🙂

              Write a Reply...