-2

How do i force remove a single and double quotation whenever they are detected before i insert them to a table in the database? Whenever i read a data in the database with a quotation and single quotation, i am encountering problems.

Here is the code that i have tried.

<?php
$string = "sample 'word' with a quotation";
$string = preg_replace("/<!--.*-->/", "", $string);
echo $string;
?>

My code isn't working. Are there any better options?

1
  • Stripping quotes out of a string is not the way to handle them. You should deal with them appropriately by escaping them or using prepared statements to insert them in your database. Anything else is almost certainly a really bad practice.
    – user1864610
    May 29, 2014 at 4:33

1 Answer 1

1
$string = "sample 'word' with a quotation";
$string = str_replace(array("'",'"'), "", $string);
echo $string; // sample word with a quotation

Not the answer you're looking for? Browse other questions tagged or ask your own question.