Reputation: 720
I need to have some if conditions for some special characters. So what I basically want is to add some kind of 'if letter is oe make letter = "ø"' statement. How can I achieve this?
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);
}
}
So can anyone help me out? That would be great! Thanks in advance...
Upvotes: 0
Views: 99
Reputation: 780984
You can replace the special characters with str_replace
:
$letter = str_replace(array('oe', ... more inputs),
array('ø', ... more replacements),
$letter);
Upvotes: 1