[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 327
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

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