Results 1 to 17 of 17

Thread: trim [Resolved]

  1. #1

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    trim [Resolved]

    Ok, so I'm using the trim function on a field being retrieved from a MS SQL Database. The field appears to be empty, but the following does not work.
    PHP Code:
    echo "<p class=warn>-" trim($row[5]) . "-"
    It simply outputs "- -"... with a space between the dashes. Any ideas why?
    Last edited by ober0330; May 5th, 2004 at 08:21 AM.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  2. #2
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    I am notgood at this. But you could try to put " " around the trim function like this:

    PHP Code:
    echo "<p class=warn>-" "trim($row[5])" "-"

    If that doesn't work, have you tested it without the trim function. Is it actually anything there?

    Or you could try to do the trimming before the echo line...

  3. #3
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    What you posted should work. try:
    echo $row[5]; //the value of $row[5]
    or:
    echo strlen($row[5]); //The length of the value.
    Have I helped you? Please Rate my posts.

  4. #4

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    I've tried all sorts of ways and used the strlen function. It is telling me that when there supposedly isn't anything there, the length of the string is 6 before and after the trim. Now I'm just really confused.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  5. #5
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    Originally posted by ober5861
    I've tried all sorts of ways and used the strlen function. It is telling me that when there supposedly isn't anything there, the length of the string is 6 before and after the trim. Now I'm just really confused.
    Does the data returned correlate with whats in the table?

    I'd imagain you have made an error in retrieving the data from the database. Check your query and that the column you are expecting to see corresponds to the column in your sql query.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  6. #6

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    It does correlate. The field is a varchar of length 5.... and besides, it doesn't matter what it is returning... it's showing a single space both before and after the trim.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  7. #7
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    It only trims spaces at start and end of string. Here's of an example at work:
    PHP Code:
    <?
    $a = array();
    $a[0] = " a b c ";
    $a[1] = "  d e f  ";
    $a[2] = "    g h i    ";
    echo strlen($a[2])."<br>";
    echo strlen(trim($a[2]));
    ?>
    this shows you that the lenghts are different.

    If you get rid of the strlen() bit you'll see that they output the same anyway, but the source will look different.
    Have I helped you? Please Rate my posts.

  8. #8

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    Right... I understand that. But here is what is happening: I'm printing out the raw value with a dash in front and behind.
    Code:
    "- -"
    It says that length is 6 using strlen();

    I then do a trim on what appears to be one space while strlen() says it's 6 and it outputs the SAME THING:
    Code:
    "- -"
    Do you see my frustration?
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  9. #9
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    Oh I totally see your frustration.
    try this and see what HTML the server outputs:
    PHP Code:
    echo "<p>".$row[5]."</p>"
    That'll tell you EXACTLY what row[5] is.
    Have I helped you? Please Rate my posts.

  10. #10

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    No change, still gives me a space.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  11. #11
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    Originally posted by ober5861
    No change, still gives me a space.
    can you post the HTMl it gives? is it just:
    "<p> </p>"?

    and strlen($row[5]); is still 6? Then something VERY strange is going on.
    Have I helped you? Please Rate my posts.

  12. #12
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    Take a look at your HTML source, I think you may be trying to display a field with just spaces. If that is the case the browser will only display one space.

    To see all six you'll need to convert the spaces to their HTML Entitiy equivilent: &amp;nbsp;

    Try this:
    PHP Code:
    echo ('[value]' htmlentities (trim ($row[5])) . ' [value]'); 
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  13. #13

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    Acidic, that outputs "<p> </p>".

    VisualAd, that outputs [value]&nbsp; [value].

    More ideas?
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  14. #14
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    if that is outputting:
    Code:
    <p> </p>
    Which you said, and also that:
    PHP Code:
    echo strlen($row[5]); 
    outputs 6. Which you also said. Then something damn wierd is going on. Are you sure $row is actually an array, try:
    PHP Code:
    echo count($row); 
    That should tell you how many elements there are in the array. Also try:
    PHP Code:
    echo $row
    Just to see what it outputs.
    Have I helped you? Please Rate my posts.

  15. #15
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    It is apparent that the string does not contain any white space. Try the code below and it will tell you the ascii character code of each character in your string.

    Maybe it will shed some light on your problem:
    PHP Code:
    for ($count  0$count str_len($row[5]); $count++)
      echo (
    ord (sub_str ($row[5], $count1)) . '<br />'); 
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  16. #16

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    I'm quite sure it is an array as I am able to output the rest of the elements ($row[0], $row[1], $row[2], etc.) just fine. It's like the browser won't display a blank field correctly or allow me to detect a blank field.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  17. #17

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    Ok... a light bulb just popped over my head and I have solved the problem... I've detected the content of $row[5] by saying:
    PHP Code:
    if($row[5] = "&nbsp;"
    and that appears to work as I need it to.

    Thanks for all your efforts.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width