Search code examples
phpselectexpressionenginesingle-quotes

Removing single quotes when retrieving data with php mysqli SELECT


I retrieve some database entries with php mysqli SELECT.

Some of the entries contain a single quote (ie : L'avant du bâtiment). This generates a parse error and breaks my webpage down.

Here is the query :

$themes = ee()->db->select('field_id_46')
    ->from('channel_data_field_46')
    ->get();

if ($themes->num_rows() > 0)
{
    foreach($themes->result_array() as $row)
    {
    $themesConcat = $row['field_id_46'];
    echo $themesConcat;
    }
}

How can I get rid of the quotes in the field_id_46 entries ?

Please note that the db Class belongs to the ExpressionEngine CMS core and that it should not be modified.


Solution

  • You can use str_replace() function for character replacement.

    The modified code as:

    echo str_replace("'", "", $themesConcat);
    

    Hope this helps you.