How to store escaped characters in MySQL and display them in php?

前端 未结 3 520
感情败类
感情败类 2021-01-29 01:53

For example I want to store the String \"That\'s all\". MySQL automatically escapes the \' character. How do I echo that String from the database using php but remove the \\ in

3条回答
  •  孤独总比滥情好
    2021-01-29 02:20

    At first, magic_quotes_gpc escapes the character like ' or ". You can also disable this in your php.ini. But then you should escape the things yourself that no query can get "infected". Lookup mysql injection for more information.

    When the escaped string is been written in your database. The string doesn't contain theses escape charakters and when you output them again. You should see the result as you want it.

    Me for myself prefer the method by storing everything without escapes and escape or display things when I output them. You could also easily use an str_replace("\n", "", $text) to prevent newslines are displayed.

    Greetings MRu

提交回复
热议问题