www.webdeveloper.com
Results 1 to 6 of 6

Thread: limit charcters in display text

  1. #1
    Join Date
    Jul 2004
    Location
    Vancouver, BC
    Posts
    66

    limit charcters in display text

    Hey all,

    Can anyone help me figure out a way to limit the number of characters to display in anchor text? For example, if I had:

    PHP Code:
    <a href='somepage.html'>this is the text I want to be limited</a
    and I wanted it to display:
    this is the...

    How could I do that?

  2. #2
    Join Date
    Oct 2004
    Location
    Portland, OR
    Posts
    145

    Maybe some php?

    Hi,
    I whipped up this little php script, hopefully it helps.
    PHP Code:
    <?
    // Define the Function
    function print_link($string$url){
        
    $str $string;
        list(
    $one,$two,$three) = explode(' ',$str);
        print 
    '<a href="'.$url.'">'.$one.' '.$two.' '.$three.'...';
    }
    // Print the Link
    print_link('Dan likes to drool on dogs','http://www.dandrools.com');
    ?>
    When called, this function will print out the first three words of what text you enter followed by "...". In this example, it will print "Dan likes to...".

    -Mike
    Last edited by Wart_Hog; 07-06-2005 at 09:37 PM.

  3. #3
    Join Date
    Jul 2004
    Location
    Vancouver, BC
    Posts
    66
    Nice work! That absolutely works, sweet!

  4. #4
    Join Date
    Oct 2004
    Location
    Portland, OR
    Posts
    145

    opsies!!!!

    I'm glad this helped. I must admit when I posted this, I was a bit sleep deprived and I missed a very important part: the "</a>" part. I appologize for that. Here's some non-sleepy code:

    PHP Code:
    <?
    // Define the Function
    function print_link($string$url){
        
    $str $string;
        list(
    $one,$two,$three) = explode(' ',$str);
        print 
    '<a href="'.$url.'">'.$one.' '.$two.' '.$three.'...</a>';
    }
    // Print the Link
    print_link('Dan likes to drool on dogs','http://www.dandrools.com');
    ?>

    This will now render:
    <a href="http://www.dandrools.com">Dan likes to...</a>
    -Mike

  5. #5
    Join Date
    Jul 2004
    Location
    Vancouver, BC
    Posts
    66
    S'alright,

    I would never expect anybody to do ALL the thinking for me! Thanks for the help!

    BTW - in your example, my 80's brain keeps finishing the szentence as "Dan likes to..." - PARTY ALL THE TIME, PARTY ALL THE TIME, PARTY ALL THE TIIIIME. From Eddie Murphy's eighties music album, believe it or not! Anyway, ahem, back to work....
    Last edited by Che; 07-11-2005 at 01:13 PM.

  6. #6
    Join Date
    Oct 2004
    Location
    Portland, OR
    Posts
    145
    Your welcome...
    I've been a bit 90's the past 2 days. I get this in my head:

    Dan likes to... punp up the jam a little more get your doggy droolin' on the dance floor.

    but thats just me...

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