Solved

Textarea to MySQL adds tab

Posted on 2013-01-19
8
313 Views
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.
0
Comment
Question by:Gary
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 38797549
Uhh, not sure but have you tried trim() right before preparing the data element?
0
 
LVL 82

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.
0
 
LVL 58

Author Comment

by:Gary
ID: 38797661
Already tried trim to no effect
@Dave
But in an editor they still should show - which they don't...
0
 
LVL 11

Expert Comment

by:mcnute
ID: 38798225
Have you tried this:

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

Open in new window


Where $text is your $_POST['description']; variable
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 108

Expert Comment

by:Ray Paseur
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?
0
 
LVL 58

Accepted Solution

by:
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...
0
 
LVL 82

Expert Comment

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

Author Closing Comment

by:Gary
ID: 38826207
Realised my own stupidity
0

Featured Post

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

746 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now