DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: In search of ... a way to kill tabs  (Read 6,463 times)

barney

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,294
In search of ... a way to kill tabs
« on: August 17, 2011, 03:41 AM »
OK, this one seems a bit stupid ... I seem to do a lot of those, don't I :(?

I'm in process of rebuilding a box that crashed.  Part of that rebuilding involves rewriting segments of PHP code that were lost.  Mostly, that's going well, but there's one problem that seems unresolvable. 

This script uses MySQL as part of the record keeping.  But whenever I try to populate an HTML textarea from a text column in the tables, it's always prefaced by either five (5) or six (6) tab characters.  None of the trim() functions are effective.  I can find many Google references to adding tabbing capability, but none, so far, to eradicating them.  I've checked - and rebuilt - the tables with several different versions of MySQL, even tried different versions of PHP.  The PHP SQL is simple -

Code: (php)
select NoteContent from notes where NoteKey=n
$notes=trim($notes)
insert into notes (NoteContent) values (\$note\")
or
update notes set NoteContent=\"$note\" where NoteKey=n
I left out some of the script, the if/then/else structures, but what's there is the relevant stuff.  The textarea bit is just
Code
<... type=textarea ...><php? echo $note ?></textarea>
But every time, the textarea shows the text with leading tabs, tabs that do not exist in the table's text field.  Oh, yeah, it's not browser-specific.  I've tried FF 3.x, FF 6, IE9, Safari, Opera, all with the same result.  These tabs are pulling my cork - something that seems easily accomplished, lately -and I've run out of places to look for an answer, save for DC.

Anybody got any ideas?
Make a good day ... barn

hamradio

  • Amateur Radio Guy
  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 893
    • Plugin Coding Medal
    • Participated in NANY Challenge Fifteen Times
    • Cody Award
    • Coding Snacks
    • Volunteers/Staff
    • Hardware Hacker
Re: In search of ... a way to kill tabs
« Reply #1 on: August 17, 2011, 03:58 AM »
Should $notes=trim($notes) be $note=trim($note);?

barney

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,294
Re: In search of ... a way to kill tabs
« Reply #2 on: August 17, 2011, 04:34 AM »
Yeah ... I was ad-libbing that, not copy-and-pasting.  Way too much code to paste, anyway.  However, the actual PHP is correct in terms of spelling - one of my favorite errors is typos or a missing ),}," or ;, so I keep a list of all vars in a separate document, and compare frequently.  However, typos won't account for the prefacing tabs in three (3) textarea constructs.  For what it's worth, I've had a friend check my code, and she doesn't find anything erroneous - apart from a few of the aforementioned typos  :P. 

Due to time constraints, I'm trying not to rewrite this thing from scratch, have mostly succeeded, save for this one problem.
Make a good day ... barn

hamradio

  • Amateur Radio Guy
  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 893
    • Plugin Coding Medal
    • Participated in NANY Challenge Fifteen Times
    • Cody Award
    • Coding Snacks
    • Volunteers/Staff
    • Hardware Hacker
Re: In search of ... a way to kill tabs
« Reply #3 on: August 17, 2011, 04:43 AM »
Could maybe try...

Code
$note = str_replace("\t","",$note);

barney

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,294
Re: In search of ... a way to kill tabs
« Reply #4 on: August 17, 2011, 06:24 AM »
OK, I had tried
Code
$studentnote=trim($studentnote,"\t")
without success, both with and without the "\t" element.  When I tried
Code
$studentnote=str_replace("\t","",$studentnote)
I lost the note altogether, although the tabs were still there  >:(.

I think I've tried every replacement function in the PHP docs, w/o success  :mad:.

As Yul Brynner once said, "Is a puzzlement."
Make a good day ... barn

justice

  • Solve issues simply.
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • Participated in NANY Challenge Four Times
    • Cody Award
    • Coding Snacks
    • DJ Badge - DJ
Re: In search of ... a way to kill tabs
« Reply #5 on: August 17, 2011, 09:25 AM »
#1
Replace <php? echo $note ?>
with
<?php echo $note; ?>

#2
if you replace it with <?php echo "";?> are the tabs still there?

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,652
    • Cody Award
    • Participated in NANY Challenge Five Times
Re: In search of ... a way to kill tabs
« Reply #6 on: August 17, 2011, 12:03 PM »
Just out curiosity...(given that you've already tried the most common correct answers)... Have you considered that something later in the code could be putting the tabs back in?

I've gotten had by that one once or twice.

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,652
    • Cody Award
    • Participated in NANY Challenge Five Times
Re: In search of ... a way to kill tabs
« Reply #7 on: August 17, 2011, 12:20 PM »
Have you seen/tried this one?

http://stackoverflow.com/questions/1181559/how-do-i-replace-tabs-with-spaces-within-variables-in-php

barney

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,294
Re: In search of ... a way to kill tabs
« Reply #8 on: August 17, 2011, 03:52 PM »
Hm-m-m ... I don't thimk anything is throwing tabs in before storing the note, but I'll have another look.

And that still wouldn't 'splain why trim() & ltrim() aren't doing their job after I extract the note. 

Is there some character, maybe Unicode, that represents a tab w/o actually being a tab?  Or, perhaps, a textarea
Code
 configuration that automatically prefixes content?  Yeah, I know, that's [i]reaching[/i], but when logic fails, sometimes the illogical will work  :P.

Oh, on the typos:  I'm typing this in on the fly, not pasting from the actual code - that's why there are so many missing ; and such.  However, using several different IDEs - Komodo, CodeLobster for PHP, Rapid PHP 2010 - for testing purposes assures me that there are no typos in the code.  (I just wish one of those IDEs would let me step through the code.  CodeLobster has a start on that, but ...)

One other thing ... this seemingly applies only to the textarea element.  Just did a quick test on a [i]type="text"[/i] element - no tabs.  In hindsight, I shoulda done that long ago, but then hindsight is always so much better  :tellme:.  Oh, and one text area on this page always prefixes six (6) tabs, the other five (5) tabs  :(.  And this seems to happen only on one page.  (I'm going through the include() files now to see if anything there might be a cause.)
Make a good day ... barn

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,652
    • Cody Award
    • Participated in NANY Challenge Five Times
Re: In search of ... a way to kill tabs
« Reply #9 on: August 17, 2011, 04:42 PM »
Is there some character, maybe Unicode, that represents a tab w/o actually being a tab?  Or, perhaps, a textarea
Code
 configuration that automatically prefixes content?  Yeah, I know, that's [i]reaching[/i], but when logic fails, sometimes the illogical will work  :P.[/quote]

A string of spaces will leave a gap in the output, but tabs don't seem to work that way:
[code=html4strict]
<textarea rows="2" name="S1" cols="20">     food</textarea>
[/code]

I too resort to illogic at times.

Original address: https://www.donationcoder.com/forum/index.php?topic=27658.0