我需要一些特殊字符的 if 条件。所以我基本上想要的是添加某种 'if letter is oe make letter = "ø"' 语句。我怎样才能实现这个目标?
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);
}
}
那么有人可以帮我吗?那太好了! 提前致谢...
最佳答案
您可以使用str_replace
替换特殊字符:
$letter = str_replace(array('oe', ... more inputs),
array('ø', ... more replacements),
$letter);
关于PHP 插入 if 条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22833134/