/    Sign up×
Community /Pin to ProfileBookmark

limit text display

(I already posted this in css, but I thought i would post it here as well…)

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:

[code=php]
<a href=’somepage.html’>this is the text I want to be limited</a>
[/code]

and I wanted it to display:
[URL=http://someurl.com]this is the…[/URL]

How could I do that?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@buntineJul 07.2005 — With which technology? I presume your generating the content dynamically, otherwise it would simply be a matter of only typing "this is the...".

Regards.
Copy linkTweet thisAlerts:
@CheauthorJul 07.2005 — yeah, good point. Im using php to generate the page, i ended up writing my own truncate function and calling it when adding the $text variable.

My truncate function looks like this:

[code=php]
function truncate($word){

for($i=0;$i<5;$i++){
$trunword.= $word[$i];
}
$trunword .= "...".strrchr($word, ".");
return $trunword;
}
[/code]


I call it like this:

[code=php]
<a href='someurl.com'><?php truncate($linktext) ?></a>
[/code]


and of course, this would be in some recusive function that genetrated a list. I should've made a clearer example, but it's end of my workday - I'm off. Anywho, thanks for the support! I was hoping there would be some little unknown javascript or attribute trick for limiting text, but i guess thats only for form text components. Ah, well... so be it.

EDIT - I forgot to mention that in this casem, I am iterating through a directory - so the text will have extensions, which is why i add the extension at the end of the trunword var. Heh, wow, I'm really unclear here, hope this helps somebody...
Copy linkTweet thisAlerts:
@KorJul 07.2005 — you mey use the [b]substring(start,end)[/b] method
[code=php]
<script type="text/javascript">
var s = 'this is the text I want to be limited';
onload = function(){
alert(s.substring(0,11)+'...')
}
</script>
[/code]
Copy linkTweet thisAlerts:
@CheauthorJul 08.2005 — Heh. Yep, that would've saved me some time, ?. Thanks!
×

Success!

Help @Che spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...