www.webdeveloper.com
Results 1 to 5 of 5

Thread: substr trouble

  1. #1
    Join Date
    Mar 2007
    Posts
    5

    substr trouble

    Hi;
    When i enter these codes
    PHP Code:
    $lasttw "<a href=\"$row[fullurl]\">$row[fullurl]</a><br />";
    $lasttwshort = (strlen($lasttw)>53)?substr($lasttw,0,53).'...<br />':$lasttw;
    echo 
    "$lasttwshort"
    or

    PHP Code:
    $lasttw "<a href=\"$row[fullurl]\">$row[fullurl]</a><br />";
    if (
    strlen($lasttw) > 53) {
      
    $lasttw substr($lasttw053) . "...<br />";
    }
    echo 
    "$lasttw"
    i'm getting page like this;

    Code:
    http://www.yahoo.comhttp://www.youtu...
    http://www.foru...
    http://www.sitepoin...
    http://http...
    http://www.boardz...
    http://www.gamezo...
    http://rapidshare.dehttp://killervide.com...
    http://www.forum...
    http://www.forum...
    ...
    ...
    http://
    ...
    but i wanna get page like this;

    Code:
    http://www.yahoo.com/
    http://www.sitepoint.com/forums/newthread.php?do=newt...
    etc
    (if the link is longer than 53 chars substr should add "..." automatically)

    Thanks for your help...Have a nica day...

  2. #2
    Join Date
    Jun 2004
    Posts
    220
    Something like this?

    PHP Code:
    $fullurl $row["fullurl"];
    if (
    strlen($fullurl) > 53) {
        
    $showurl substr($fullurl053) . "...";
    }else{
        
    $showurl $fullurl;
    }

    $lasttw "<a href=\"$fullurl\">$showurl</a><br />";

    echo 
    "$lasttw"
    Lubox

  3. #3
    Join Date
    Mar 2007
    Posts
    5
    Thanks Lubox. You are great!

  4. #4
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    Or this:
    PHP Code:
    <?php
    $showurl 
    strlen($row['fullurl']) > 53) ? substr($row['fullurl'],0,53) . "..." $row['fullurl'];

    $lasttw "<a href='{$row['fullurl']}'>$showurl</a><br />";

    echo 
    "$lasttw"
    ?>

  5. #5
    Join Date
    Mar 2007
    Posts
    5
    NightShift58, thank you too.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles