php string escaping like python's “”“ ”“”?

前端 未结 3 945
Happy的楠姐
Happy的楠姐 2021-01-20 11:32

Hi I was wondering if there is an easy way to escape strings in php.

In python I use \"\"\" \"\"\", and everything between there is escaped. so when using special c

3条回答
  •  时光取名叫无心
    2021-01-20 11:41

    There are various functions depending on what you want to escape.

    If you are using a lot of double quotes, for example with html, you can wrap the string in single quotes to prevent having to escape.

    $string = 'no escape needed';
    

    The same goes the other way

    $string = "I'd rather be gaming";
    

    Then you have a couple of functions used mostly for escaping user input:

    addslashes() that will escape quotes
    htmlspecialchars() will 'escape' html codes
    mysql_real_escape_string() for escaping mysql input

提交回复
热议问题