Welcome Guest, Not a member yet? Register   Sign In
Why can't I use trim() in CodeIgniter 3.0?
#1
Lightbulb 

Because of the version of apache and php, I cannot use CI's form_validation library and filter function, I have to write some native code to filter the special character. However, I cannot use trim() on model or controller, even though I add $this->load->library('string'). Anyone knows how to solve it? Or anyone give me some suggestion to do it without using CI's form validation. Thank you!
Reply
#2

The function trim() is a native php function, so it should work, whether you use CodeIgniter or not.
Please give us an example of your code that won't work.
Reply
#3

The code is pretty simple, $data['inputAddressLine1'] = trim($_POST['inputAddressLine1']); This line is in the controller, but when I use $data in the View($inputAddressLine1), the multiple white space cannot be removed, I am really confused with it.
Reply
#4

If the version of Apache and PHP you are using is preventing you from using CI's form_validation library, I don't really know how we're going to be able to help you re-implement the library in whatever version of PHP you are using.

If trim() isn't removing whitespace, that implies that one of the following is true:
- the whitespace is inside the string, not on the right or left edge of the string
- the whitespace is something else which trim() won't remove by default (the manual tells you which 6 characters are interpreted as whitespace)
- trim() is removing the whitespace, but you're not looking at the result of trim()
Reply
#5

Try using CodeIgniters input.

PHP Code:
$this->input->post('something'); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#6

(07-23-2015, 03:38 PM)InsiteFX Wrote: Try using CodeIgniters input.



PHP Code:
$this->input->post('something'); 

Still doesn't work, I have no idea. But without using CI, trim() works. I give up solving this problem, because if the apache does not allow me to use almost all useful library and function of CI, this framework is useless in another word. 
Thank you guys for all your help!
Reply
#7

(07-23-2015, 05:00 PM)xietao0221 Wrote: Still doesn't work, I have no idea. But without using CI, trim() works. I give up solving this problem, because if the apache does not allow me to use almost all useful library and function of CI, this framework is useless in another word.  Thank you guys for all your help!

What version of Apache and PHP are you using? It really sounds like there's something else wrong here and you're just trying to work around a bigger issue that might be more easily fixed by taking it on directly.
Reply
#8

I believe it's just a logical error in your code and you've shown none of it so far ...
Reply
#9

What Narf said, and are you getting an error, a white screen, or what? Show something to us.
Reply
#10

This is what I call a chair to interface error. Quit blaming the framework Wink
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
Reply




Theme © iAndrew 2016 - Forum software by © MyBB