0

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...

10
  • What problem are you getting with your code? Commented Apr 3, 2014 at 9:23
  • Sounds like you're looking for str_replace(). Commented Apr 3, 2014 at 9:23
  • You can replace all those OR conditions with formated_name RLIKE '^[0-9#]'. Commented Apr 3, 2014 at 9:25
  • @Barmar what about the if($letter == '0-9)-statement? Shouldnt I add the special letters (danish) like Æ,Ø,Å somehow? Commented Apr 3, 2014 at 9:29
  • I don't see what this has to do with the if statement. You just need to do use str_replace to replace these things with what you want. Commented Apr 3, 2014 at 9:34

1 Answer 1

1

You can replace the special characters with str_replace:

$letter = str_replace(array('oe', ... more inputs),
                      array('ø', ... more replacements),
                      $letter);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.