Solved

Textarea to MySQL adds tab

Posted on 2013-01-19
8
319 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 109

Expert Comment

by:Ray Paseur
ID: 38797549
Uhh, not sure but have you tried trim() right before preparing the data element?
0
 
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.
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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
 
LVL 109

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 83

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

813 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

10 Experts available now in Live!

Get 1:1 Help Now