limit charcters in display text

liunx

Guest
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:


<a href='http://www.webdeveloper.com/forum/archive/index.php/somepage.html'>this is the text I want to be limited</a>


and I wanted it to display:
this is the... (<!-- m --><a class="postlink" href="http://someurl.com">http://someurl.com</a><!-- m -->)

How could I do that?Hi,
I whipped up this little php script, hopefully it helps.

<?
// Define the Function
function print_link($string, $url){
$str = $string;
list($one,$two,$three) = explode(' ',$str);
print '<a href=http://www.webdeveloper.com/forum/archive/index.php/"'.$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...".

-MikeNice work! That absolutely works, sweet!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:

<?
// Define the Function
function print_link($string, $url){
$str = $string;
list($one,$two,$three) = explode(' ',$str);
print '<a href=http://www.webdeveloper.com/forum/archive/index.php/"'.$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.webdeveloper.com/forum/archive/index.php/"http://www.dandrools.com">Dan likes to...</a>


-MikeS'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....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...
 
Back
Top