我需要为某些特殊字符设置一些if条件。所以我基本上想要的是添加某种'如果是写字母=“ø”'的话。我怎样才能做到这一点?
public function letter_get($letter)
{
$this->load->database();
if($letter == '0-9')
{
$where = "formated_name LIKE '0%' OR formated_name LIKE '1%' OR formated_name LIKE '2%'
OR formated_name LIKE '3%' OR formated_name LIKE '4%' OR formated_name LIKE '5%' OR formated_name LIKE '6%' OR formated_name LIKE '7%' OR formated_name LIKE '8%' OR formated_name LIKE '9%' OR formated_name LIKE '#%'";
}
else
{
$where = "formated_name LIKE '".$letter."%'";
}
$sql = "SELECT artist_id, formated_name FROM artists WHERE ".$where;
$query = $this->db->query($sql);
$data = $query->result();
if($data) {
$this->response($data, 200);
} else {
$this->response(array('error' => 'Couldn\'t find any artists with this letter!'), 404);
}
}
那么有人可以帮助我吗?那太好了! 提前谢谢......
答案 0 :(得分:1)
您可以使用str_replace
替换特殊字符:
$letter = str_replace(array('oe', ... more inputs),
array('ø', ... more replacements),
$letter);