TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-13-2010, 06:37 PM   #1 (permalink)
The Acquainted
 
Join Date: Feb 2008
Posts: 107
Thanks: 3
CΛSTΞX is on a distinguished road
Arrow Crop Content

Hello, this snippet crops the content and puts "..." to the end. My question is, how can I get the rest of the content ?

PHP Code:
<?

$str 
"Yeah, but on my website, before I realized that converting quotes, etc, to entities was a bad idea, I already had a lot of stuff put into a database...Also, symbols like show up as question marks... and I don't really know how to fix that. In my four years of HTML experience, and two years of PHP experience, I've never been able to get character encoding to do what I want it to.";

$chars "150";

function 
shortText($str$chars)
{
if (
strlen($str) > $chars)
    {
    
$str substr($str0$chars);
    
$str $str "...";
    return 
$str;
    }
else
    {
return 
$str;
    }
}

echo 
shortText($str$chars);

?>
__________________
Downloadic
infolizer
Send a message via MSN to CΛSTΞX
CΛSTΞX is offline  
Reply With Quote
Old 01-13-2010, 09:08 PM   #2 (permalink)
The Wanderer
Newcomer 
 
Parvus's Avatar
 
Join Date: Aug 2008
Posts: 21
Thanks: 1
Parvus is on a distinguished road
Default

Do you mean like this ?
PHP Code:
<?

$str 
"Yeah, but on my website, before I realized that converting quotes, etc, to entities was a bad idea, I already had a lot of stuff put into a database...Also, symbols like show up as question marks... and I don't really know how to fix that. In my four years of HTML experience, and two years of PHP experience, I've never been able to get character encoding to do what I want it to.";

$chars "150";

function 
shortText($str$chars)
{
if (
strlen($str) > $chars)
    {
    
$str substr($str0$chars);
    
$str $str "<a href='/link-to-full-article.html'>...</a>";
    return 
$str;
    }
else
    {
return 
$str;
    }
}

echo 
shortText($str$chars);

?>
So you can click on the 3 dots to go to the full page ?
or do you just mean echo($str); ?
Parvus is offline  
Reply With Quote
Old 01-13-2010, 09:58 PM   #3 (permalink)
The Acquainted
 
Join Date: Feb 2008
Posts: 107
Thanks: 3
CΛSTΞX is on a distinguished road
Default

I just want to get the section which starts with "..." (script does this after 150 chars) and finishes at the end.
__________________
Downloadic
infolizer
Send a message via MSN to CΛSTΞX
CΛSTΞX is offline  
Reply With Quote
Old 01-14-2010, 07:38 PM   #4 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Well since the above code isn't worried about cropping at a space or punctuation, I won't worry either. :)

php Code:
$remainder = substr( $str, $chars );
delayedinsanity is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Create Content with XML and parse... buildakicker XML, XSLT, XPath, XQuery 4 03-05-2013 07:44 AM
Edit posted form content & if isset quesion Peuplarchie Advanced PHP Programming 1 11-09-2008 11:34 PM
encoding cookie content Devels General 7 02-21-2008 01:56 PM
where to start when wanting to learn how to make a content management system sarmenhb General 8 02-05-2008 05:06 PM
how to search the content of txt file meshi Absolute Beginners 11 11-01-2007 04:43 PM


All times are GMT. The time now is 09:59 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design