General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old March 9th, 2003, 08:20 AM
guitarnoise guitarnoise is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 32 guitarnoise User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Limiting string output

This may seem like a really simple question, but I haven't been able to find anything in the forums or even the php manual. I guess I don't really know what I'm looking for. I think I am trying to limit the output of a string.

You know on a content driven website where the index page has the latest articles and the text describing the article is the first few sentences of the article? How can set something so that only the first 200 characters or so of the article body are displayed on an index page? I know this is probably beginner stuff but I've been reading tutorials and searching all over. I couldn't find what I was looking for.
__________________
Without me my guitar is useless
--
http://www.guitarnoise.com
http://www.musiccareers.net

Last edited by guitarnoise : March 9th, 2003 at 08:59 AM.

Reply With Quote
  #2  
Old March 9th, 2003, 11:24 AM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
I dunno about that,....what I did though is have a summary field in which you only allow,..say 200 characters to be posted?
__________________
-- Jason

Reply With Quote
  #3  
Old March 9th, 2003, 07:13 PM
guitarnoise guitarnoise is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 32 guitarnoise User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Actually, that is what I am using at the moment - a summary field. It works fine, but in some cases I want to use the first few lines from an article and it would save work repeating myself.

Reply With Quote
  #4  
Old March 10th, 2003, 12:41 AM
MERSAL MERSAL is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 7 MERSAL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Ok this really simple , you can use Regular Expression Functions to do that ... I will explain more with exempla :


supposed we have this article :


so many of my friends interesting to learn more about web dev.

We want show this part from article in first page (learn more about web dev.)

just we will put this tag [fpage] in beginning of part and [/fpage] in end

will be looking like that in data base ..
so many of my friends interesting to [fpage]learn more about web dev.[/fpage]

We will only cut characters between tags by Regular Expression
look simple


PHP Code:
 $article1="so many of my friends interesting to [fpage]learn more about web dev.[/fpage] ";

 
preg_match("/(\[)(fpage)(])(\r\n)*(.*)(\[\/fpage\])/esiU",$article1,$article2);
echo 
article2


I wish this helpful

Sorry on my English

Reply With Quote
  #5  
Old March 10th, 2003, 09:25 AM
guitarnoise guitarnoise is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 32 guitarnoise User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
This works I suppose. But it still has a bit of extra work involved as an human editor would have to manually set different tags for each entry in the database. I was looking for something more automatic, like only showing a set number of characters as summary or just including the first paragraph.

Anyone have more ideas?

Reply With Quote
  #6  
Old March 11th, 2003, 03:19 AM
MERSAL MERSAL is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 7 MERSAL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0


I supposed you want particular characters ...

this may be help you :

PHP Code:
<?php
$text 
"so many of my friends interesting to learn more about web dev. ";
echo 
strlen($text) ;
$maxTextLenght=50;
  
$aspace=" ";
  if(
strlen($text) > $maxTextLenght ) {
     
$text substr(trim($text),0,$maxTextLenght); 
     
$text substr($text,0,strlen($text)-strpos(strrev($text),$aspace));
    
$text $text.'...';
  }
  echo 
'<br>';
  echo 
$text;
?>


You must assign max text lenght in $maxTextLenght

This from PHP.net from commnets

Last edited by MERSAL : March 11th, 2003 at 03:26 AM.

Reply With Quote
  #7  
Old March 12th, 2003, 05:39 PM
guitarnoise guitarnoise is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 32 guitarnoise User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Thanks for the help. That last example helped me figure out exactly what I needed.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Limiting string ourput


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway