Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How to handle quote characters in PHP?

characters php Quote
0
Posted

How to handle quote characters in PHP?

0

As you know, Firebird escapes the single-quote (apostrophe) character in strings with another quote character. For example to store string “can’t” into database you would write a query like this: INSERT INTO t1 VALUES (‘can”t’); The same thing should be done with PHP when you supply values as strings (i.e. you build the entire statement as a string): ibase_query(‘INSERT INTO t1 VALUES (\’can\’\’t\’)’); or ibase_query(“INSERT INTO t1 VALUES (‘can”t’)”); If you have values in variables, you can escape them using str_replace: $cant = “can’t”; $cant = str_replace(“‘”, “””, $cant); ibase_query(“INSERT INTO t1 VALUES(‘$cant’)”); Of course, using strings to build queries is not a very good idea. You should use parametrized queries and then you wouldn’t have to escape anything. You probably knew all this, now onto the advanced stuff. When variables are supplied by the user using a form (via GET or POST) PHP might change them. For example, when user types: can’t into a form field, you might

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123