Textarea to MySQL adds tab

Posted on 2013-01-19
Last Modified: 2013-01-28
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.
Question by:Gary
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
LVL 110

Expert Comment

by:Asked Anonymously
ID: 38797549
Uhh, not sure but have you tried trim() right before preparing the data element?
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38797557
Echoing the data in HTML is misleading because HTML ignores tabs and other control characters.  It may display them as a space.
LVL 58

Author Comment

ID: 38797661
Already tried trim to no effect
But in an editor they still should show - which they don't...
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

LVL 11

Expert Comment

ID: 38798225
Have you tried this:

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

Open in new window

Where $text is your $_POST['description']; variable
LVL 110

Expert Comment

by:Asked Anonymously
ID: 38798297
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?
LVL 58

Accepted Solution

Gary earned 0 total points
ID: 38799148
Found the problem - there were tabs before and after <?=$description?> which were being added into the textarea.  

Stupid I know...
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38799397
Glad you found it.
LVL 58

Author Closing Comment

ID: 38826207
Realised my own stupidity

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP Curl Problem 10 66
MySQL HA and DR solution. 5 32
Bootstrap - BootBox - PHP - MYSQL - Response Trigger 6 49
SQL Procedure 7 44
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question