-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?

Christian Burgos
  • 1,572
  • 9
  • 26
  • 48
  • 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. –  May 29 '14 at 04:33

1 Answers1

1
$string = "sample 'word' with a quotation";
$string = str_replace(array("'",'"'), "", $string);
echo $string; // sample word with a quotation
Mark Miller
  • 7,442
  • 2
  • 16
  • 22