使用 php mysqli SELECT 检索数据时删除单引号
Removing single quotes when retrieving data with php mysqli SELECT
我用 php mysqli SELECT 检索了一些数据库条目。
一些条目包含单引号(即:L'avant du bâtiment)。这会产生解析错误并破坏我的网页。
这里是查询:
$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;
}
}
如何去掉 field_id_46 条目中的引号?
请注意,数据库 Class 属于 ExpressionEngine CMS 核心,不应修改。
您需要对字符进行转义。您可以使用 php 的方法添加斜杠,如下所示:
echo addslashes($themesConcat);
可以使用str_replace()
函数进行字符替换。
修改后的代码为:
echo str_replace("'", "", $themesConcat);
希望对您有所帮助。
我用 php mysqli SELECT 检索了一些数据库条目。
一些条目包含单引号(即:L'avant du bâtiment)。这会产生解析错误并破坏我的网页。
这里是查询:
$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;
}
}
如何去掉 field_id_46 条目中的引号?
请注意,数据库 Class 属于 ExpressionEngine CMS 核心,不应修改。
您需要对字符进行转义。您可以使用 php 的方法添加斜杠,如下所示:
echo addslashes($themesConcat);
可以使用str_replace()
函数进行字符替换。
修改后的代码为:
echo str_replace("'", "", $themesConcat);
希望对您有所帮助。