Membership is FREE, giving all registered users unlimited access to every Acorn Domains feature, resource, and tool! Optional membership upgrades unlock exclusive benefits like profile signatures with links, banner placements, appearances in the weekly newsletter, and much more - customized to your membership level!

PHP help

Status
Not open for further replies.
Joined
Mar 13, 2005
Posts
4,662
Reaction score
184
Can any PHP geniuses help me out here, here is what I want to do:

if length of $string > 50 then $string = first 50 characters + "....."


Thanking you kindly

Grant
 
$string = (strlen($string)>50) ? substr($string,0,50).'…' : $string;

Jee
 
If you're creating an excerpt then that'll sometimes cut you off in the middle of words.

You can avoid this by trimming the output of the above and removing anything between the last word boundary and the end of the string.

Code:
$string = preg_replace('/\b.*$/', '', $string);

Even smarter excerpts can be created by looking for whole sentences. Though with only 50 characters you probably won't get many of them.
 
Thanks for the assistance chaps, very helpful and much appreciated.

Grant
 
Status
Not open for further replies.

Rule #1: Be Respectful

Do not insult any other member. Be polite and do business. Thank you!

Members online

Premium Members

Latest Comments

Upcoming events

New Threads

Domain Forum Friends

Lastest Listings

Our Mods' Businesses

*the exceptional businesses of our esteemed moderators
General chit-chat
Help Users
  • No one is chatting at the moment.
      There are no messages in the current room.
      Top Bottom