How to Delete a character from a string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chazzy69
    New Member
    • Sep 2007
    • 196

    How to Delete a character from a string

    Hi this is probably a very simple question but how do you remove characters from strings i have already tried ltrim and str_replace but the certain character still stayed in the string.

    Not sure if its just the character im searching for or if its the function itself which is screwing up.

    Any how the actual character is --> ' <-- in other words an Apostrophe and here is an example of the string im trying to remove it from
    --> "Here's a fantastic opportunity".

    The reason im trying to do this is because when i write to a database i get an error with this specific character so i thought just remove it.

    Thanks for any help in advanced,
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    i don't see why str_replace wouldn't work..

    But anyway, the problem you're encountering is not the problem you think it is, but a security risk. Read mysql_injection (). You can over come this by using mysql_real_esca pe_string().

    Kind regards.

    Comment

    • hsriat
      Recognized Expert Top Contributor
      • Jan 2008
      • 1653

      #3
      You need addslashes.

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by hsriat
        You need addslashes.
        But when dealing with a DataBase, I think it's more ideal to use mysql_real...() because it escapes all special characters concerned with a DB.

        Comment

        • chazzy69
          New Member
          • Sep 2007
          • 196

          #5
          Ok i understand that such characters can be used to determine wether a database is susceptable to injections, but this is not some much the reason im doing this its more the reason im trying to store data and the appostrephe is screwing this up.

          So i looked at both the escape characters and the addslahes, the escape characters look more like what i need but only a slight problem i cant read german and don't understand the explanations of each of the parameters of the function.

          So could you please post a reasonably example of this function in action.

          Thanks for the help

          [EDIT]

          Lol i didn't realise that you change the page to english, anyway i understand the function now but can i use the function without a link indentifyier; Can this function be used on a straight string in php without anything to do with mysql??

          Becuase i want to remove any specail characters before making any my_sql connections

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Originally posted by chazzy69
            Ok i understand that such characters can be used to determine wether a database is susceptable to injections, but this is not some much the reason im doing this its more the reason im trying to store data and the appostrephe is screwing this up.

            So i looked at both the escape characters and the addslahes, the escape characters look more like what i need but only a slight problem i cant read german and don't understand the explanations of each of the parameters of the function.

            So could you please post a reasonably example of this function in action.

            Thanks for the help

            [EDIT]

            Lol i didn't realise that you change the page to english, anyway i understand the function now but can i use the function without a link indentifyier; Can this function be used on a straight string in php without anything to do with mysql??

            Becuase i want to remove any specail characters before making any my_sql connections
            There has to be a mysql connection present for this to work.

            It'll make no difference if you do the escaping after the connection is established. You don't *need* a link identifier; the last connection will be assumed.

            Comment

            • chazzy69
              New Member
              • Sep 2007
              • 196

              #7
              Ok i have solved my problem and i didn't actually needed the escape characters msql function due to the fact that it would have deleted some of the stuff im trying to save into my database.

              But anyway the problem was, i was using the str_ireplace function incorrectly thanks for the help anyway. And i will try to remember that escape characters function for future reference.


              Thanks for all your help

              Comment

              Working...