Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 329
  • Last Modified:

Textarea to MySQL adds tab

When saving the contents of a textarea to MySQL into a blob field using PDO I get 6 tabs added to the beginning of the data and 4 tabs added to the end (that is tabs as in if you pressed the TAB key)
Is there something special I should be doing for a textarea?
This is a just a normal prepare statement followed by execute(array etc and assigning the post value of the textarea to a value for the prepare statement.
':description' => $_POST['description']

The posted data does not contain the tabs - I checked by echoing out the post value.
0
Gary
Asked:
Gary
  • 3
  • 2
  • 2
  • +1
1 Solution
 
Ray PaseurCommented:
Uhh, not sure but have you tried trim() right before preparing the data element?
0
 
Dave BaldwinFixer of ProblemsCommented:
Echoing the data in HTML is misleading because HTML ignores tabs and other control characters.  It may display them as a space.
0
 
GaryAuthor Commented:
Already tried trim to no effect
@Dave
But in an editor they still should show - which they don't...
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
mcnuteCommented:
Have you tried this:

$text = preg_replace("/\s+/", " ", $text);  

Open in new window


Where $text is your $_POST['description']; variable
0
 
Ray PaseurCommented:
If trim($_POST['description']) did not do the job, then I think we need to see a little more deeply into the problem.  Can you determine exactly when the addition of the tabs occurs?  For example, if you use phpMyAdmin to examine the data base do you detect the tabs in the column?  If you change the column type to TEXT does the problem still present?  Can you produce the SSCCE so we can install a parallel script and try it on our servers?
0
 
GaryAuthor Commented:
Found the problem - there were tabs before and after <?=$description?> which were being added into the textarea.  

Stupid I know...
0
 
Dave BaldwinFixer of ProblemsCommented:
Glad you found it.
0
 
GaryAuthor Commented:
Realised my own stupidity
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now