![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 | ||
Confirmed User
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,119
|
![]() Im using the following on a page to limit the amount of characters are displayed for a products description:
Quote:
Quote:
... More With a clickable link using a link setup this way: domain.com/page.php?id=$ID How would I go about editing the code I'm currently using to facilitate that? I have tried adding the HTML code next to the periods but, that didnt work for some reason ![]() Should I be using something different entirely? Any help, pointers or advice would be appreciated. Thanks ![]()
__________________
NOTHING TO SEE HERE |
||
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
Monger Cash
Industry Role:
Join Date: Jul 2010
Posts: 2,773
|
not sure why you have that broken down into 12 lines, nonetheless...
Code:
<?php $output = strlen($input) > 50 ? substr($input,0,50)."..." : $input; echo $output ?> Function method: Code:
<?php $x = "This is a test of the emergency broadcast system. This is only a test. If this were a real emergency, you'd be dead"; $length = 50; function truncate_text($x, $length) { $output = strlen($x) > $length ? substr($x,0,$length)."..." : $x; return $output; } echo truncate_text($x, $length); ?> Granted, this is a really archaic way of handling it given the fact you should be truncating by whole words, not single characters. The above example illustrates why (returned string is for the function above is "This is a test of the emergency broadcast system. ..." |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
Confirmed User
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,119
|
How do I change that to truncate by words instead of characters but still keep the character count as close to 100 as possible?
__________________
NOTHING TO SEE HERE |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
Monger Cash
Industry Role:
Join Date: Jul 2010
Posts: 2,773
|
Code:
<?php $input = "This is a test of the emergency broadcast system. This is only a test. If this were a real emergency, you'd likely be dead"; $length = 100; $output = strlen($input) > $length ? substr($input, 0, strpos(wordwrap($input, $length), "\n"))."..." : $input; echo $output; |
![]() |
![]() ![]() ![]() ![]() ![]() |