SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2005
    Location
    ble
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Checking a variable's lenght -- ??

    I want to check the length of the variable '.$user_arr[12].' so I created this:

    Code:
    <table>
              <tr>
                <td class="con1"><b>Forum Posts</b></td>
                <td class="con1">'.$user_arr[11].'</td>
              </tr>
    
              <tr>
                <td class="con1"><b>A bit about me</b></td>
    <? if ('.$user_arr[12].' < 0) {
    	echo "<td class=con1>None!!</td>";
    	else "<td class=con1>'.$user_arr[12].'</td>";
    ?>
              </tr>
    </table>
    And that should work all fine.. however it doesnt.. it prints out this (exactly this!):


    None!!"; else ""; ?>
    Forum Posts 0
    A bit about me


    And it makes no diffence what so ever.. Theres no parse error so the syntaxing is ok.. I hope. Someone please help me im uber fustrated :'(
    If someone was helpful, give them some 'rep'.

  2. #2
    SitePoint Wizard HarryR's Avatar
    Join Date
    Dec 2004
    Location
    London, UK
    Posts
    1,376
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    The problem you were having was due to malformed syntax,

    Here is what you can do instead:

    PHP Code:
    <table>
              <tr>
                <td class="con1"><b>Forum Posts</b></td>
                <td class="con1">'.$user_arr[11].'</td>
              </tr>

              <tr>
                <td class="con1"><b>A bit about me</b></td>
            <?php
                
    // If user_arr[12] is not set:
                
    if ( ! isset($user_arr[12]) || strlen($user_arr[12]) < )
                {
            
    ?>
                <td class="con1">None!!</td>
            <?php
                
    // Or if it is set:
                
    } else
                {
            
    ?>
                <td class="con1"><?php print ($user_arr[12]); ?></td>
            <?php
                
    }
            
    ?>
              </tr>
    </table>
    What i'm doing is checking if the $user_arr[12] variable is not set, or if the $user_arr[12] variables length (the strlen function gives you a strings length) is less than 1.

    If either of those evaluate to true, None!! is printer, otherwise the variable is printed.

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2005
    Location
    ble
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yay, it prints out None!! but even if someone has a profile it prints out this:

    A bit about me: "None!!" "This is my profile, and im really cool"

    and if someone hasnt set it it just prints:

    A bit about me: "None!!"

    P.S I had to add '. and .' on each side of the variable as im using flat-file!
    If someone was helpful, give them some 'rep'.

  4. #4
    SitePoint Zealot
    Join Date
    Jan 2005
    Location
    ble
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, nm. Its all good now!!
    If someone was helpful, give them some 'rep'.


Bookmarks

Posting Permissions

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