Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2006
    Posts
    96
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Dots ..... after a substr output

    Hi All

    Can any one help. I have a search box on my web site that echos a small part of the details, like google. I use the following for the echo.

    Code:
    <?php echo substr(($row_articles['bodytext']),0,260); ?>
    I then add dot .... with html but should the field be empty I would get the following:

    Hislop
    HISLOP.—At Goole Maternity Home, on Friday, Sept. 7th, to John and Nora (nee Sheard), a son. ...
    http://www.starlightpublishing.co.uk.../bmds.php?id=3

    Hislop
    ...
    http://www.starlightpublishing.co.uk.../bmds.php?id=3


    Is there a command that will allow the substr to insert dots only when something is echoed back that would output as such:


    Hislop
    HISLOP.—At Goole Maternity Home, on Friday, Sept. 7th, to John and Nora (nee Sheard), a son. ...
    http://www.starlightpublishing.co.uk.../bmds.php?id=3

    Hislop
    http://www.starlightpublishing.co.uk.../bmds.php?id=3



    Cheers
    Steve

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Hi,

    You could use strlen(), if it's greater than 260 concatenate the dots, otherwise only display the text:
    PHP Code:
    <?php echo (strlen($row_articles['bodytext']) > 260) ? substr(($row_articles['bodytext']),0,260) . '. ...' $row_articles['bodytext']; ?>
    Ref:
    http://us2.php.net/strlen

    Good luck;
    Last edited by Brandoe85; 10-27-2006 at 08:07 AM.

  • #3
    New Coder
    Join Date
    Jul 2006
    Posts
    96
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Cheers.

    Will give it a go later

    Steve


  •  

    Posting Permissions

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