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.

Post New Thread Reply

Register GFY Rules Calendar Mark Forums Read
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 04-12-2022, 05:13 PM   #1
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
One more quick php question

Im using the following on a page to limit the amount of characters are displayed for a products description:

Quote:
<?php

function custom_echo($x, $length)
{
if(strlen($x)<=$length)
{
echo $x;
}
else
{
$y=substr($x,0,$length) . '...';
echo $y;
}
}
?>
Followed by calling the shortened description like this:

Quote:
<?php custom_echo($row['style-info'], 100); ?>
It works perfectly however, I'm wanting to add this onto the end after the period marks:

... 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
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-12-2022, 07:13 PM   #2
vdbucks
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
?>
That's all you really need.

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);
?>
Adapt to your use case, obv.

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. ..."
vdbucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-12-2022, 09:01 PM   #3
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
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
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-13-2022, 06:20 AM   #4
vdbucks
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;
vdbucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks

Tags
code, description, link, periods, adding, html, editing, facilitate, crap, pointers, advice, appreciated, thumbsup, reason, clickable, displayed, characters, products, calling, amount, question, php, quick, limit, page
Thread Tools



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.