|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
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.
|
|
#4
|
|||
|
|||
|
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:
I wish this helpful Sorry on my English ![]() |
|
#5
|
|||
|
|||
|
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? |
|
#6
|
|||
|
|||
![]() I supposed you want particular characters ... this may be help you : PHP Code:
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. |
|
#7
|
|||
|
|||
|
Thanks for the help. That last example helped me figure out exactly what I needed.
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Limiting string ourput |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|