I have a textarea that lets users write their own input which gets saved into the database.
The majority of the users copy their text from word or similar program, which also copies their tabs into the textarea.
When the tabs get saved to the database it is automatically converting them to just one space.
I want to save the tabs as either proper tabs into the database or a set number of whitespaces, however I can’t catch the tabs in the first place.
This is what I have tried so far (after getting the input from the user and before saving to the database)
str_replace("\t", " ", $string);
str_replace(chr(9), " ", $string);
However, I can tell that the tabs aren’t even being caught because I try this:
if (strpos($string, "\t") !== false)
{
exit("The tab was found");
}
The ‘exit’ never gets called.
I have searched extensively for an answer to this, however I haven’t been able to find any fixes.
I would really appreciate some help on this one.
Nathan Bell’s comment “Is there any pre-processing being done on the form values before you see the value?”. That got me thinking.
I am using codeigniter as my php framework. After doing some research and looking at the source code I found that the built in security class was formatting all my tabs into a single space, like so…
So all I did was change the source code to this:
And it’s working now. So thank you Nathan and everyone else who assisted for the help!