I know how to replace an Apostrophe from a String with a space, in php. However how can I remove Apostrophes in arrays items?
//Example replacing Apostrophe with space
$string = str_replace("'", "", $escapestring);
if ( $f_pointer === false )
die ("invalid URL");
$ar=fgetcsv($f_pointer);
while(! feof($f_pointer))
{
$ar=fgetcsv($f_pointer);
//DO REPLACE HERE BEFORE INSERTION INTO SQL STATEMENT
$sql="INSERT INTO x
(1,2,3,4,5,6)
values('$array[0]','$array[1]','$array[2]',
'array[3]','array[4]','array[5]')";
UPDATED answer:
You want to remove apostrophe for your query. It's a better way to use function as mysqli_real_escape_string:
"(PHP 5) mysqli::real_escape_string -- mysqli_real_escape_string — Escapes special characters in a string for use in an SQL statement, taking into account the current charset of the connection" | http://php.net/manual/en/mysqli.real-escape-string.php
So you directly protect your query input against sql injection. See the following example:
$itemsToClean = ["Value with '", "Second value with '"];
// With older PHP version, you cannot use [], but use array() instead
$cleanItems = array_map('mysqli_real_escape_string', $itemsToClean);
print_r($cleanItems);
use str_replace with array as subject
$itemsToClean = ["Value with '", "Second value with '"];
$itemsToClean = str_replace("'", '', $itemsToClean);
print_r($itemsToClean);
result
Array
(
[0] => Value with
[1] => Second value with
)