0

I have something like this in a CodeIgniter Model

$query = $this->db->insert('something',$data);

if($query)
{
    return true;
}
else
{
    return $this->db->_error_message();
}

What I would very much like to know is, how can I remove the html from the error template generated by CodeIgniter, when the _error_message() function is returned, keeping just the plain error message text?

Any ideas?

3 Answers 3

1
return strip_tags($this->db->_error_message());

it will strip everything in between <> I didnt know there was any css on page but you can then parse html with dom parser and return only plaintext from div with the id or class that you want

Sign up to request clarification or add additional context in comments.

4 Comments

Haven't tried this yet, but, does this exclude the embeeded CSS that comes with the page?
no it will strip everything in between <> I didnt know there was any css on page but you can then parse html with dom parser and return only plaintext from div with the id or class that you want
That is a bit of an overkill for what I pretend to do... But you've got a point on it. Maybe you could edit your answer so I can accept it ;)
Thanks I edited it. Yes I guess its an overkill since parsing html is bound to slow things down. did you saw this topic about db errors stackoverflow.com/questions/10679714/…
0

I can't remember exactly of the top of my head but I know that you can sent customs error messages by creating a file in application/language/english

Take a look at this page in the documentation and it should help

http://ellislab.com/codeigniter/user-guide/libraries/language.html

1 Comment

But I wanted the SQL error to be retrieved. Not a custom error, although this seems a good backup plan...
0

The safest way to do it is to go to the errors folder, change your header type to text/plain. Then remove out the html formatting and echo the error messages.

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.