Linewrapping?
Moderator: General Moderators
Linewrapping?
Hi, i'm writing a site with some diffrent features. On the startpage the news are published but now i need some help. I only want the first half line or so of the news published with a few dots after and when they click on that text (being a link) they can read the entire news. I know how to write all that except the wrapping. Someone help please?
Have a look at substr() or the word breaking post in the useful posts topic.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- aerodromoi
- Forum Contributor
- Posts: 230
- Joined: Sun May 07, 2006 5:21 am
Re: Linewrapping?
You could always useduzchip wrote:Hi, i'm writing a site with some diffrent features. On the startpage the news are published but now i need some help. I only want the first half line or so of the news published with a few dots after and when they click on that text (being a link) they can read the entire news. I know how to write all that except the wrapping. Someone help please?
Code: Select all
explode(" ", $string);aerodromoi
Then go to bed and have a good sleep. You'll be more productive afterwards.. (And we don't have to waste our time giving examples that are already available in the manual...)
In case you're getting the text from a database it's a waste to fetch the complete text if you only want the first 50 words or so. In that case you can use a query like:
In case you're getting the text from a database it's a waste to fetch the complete text if you only want the first 50 words or so. In that case you can use a query like:
Code: Select all
SELECT SUBSTRING_INDEX(body,‘ ‘,50) AS introduction FROM mytable
- aerodromoi
- Forum Contributor
- Posts: 230
- Joined: Sun May 07, 2006 5:21 am
Here you go:duzchip wrote:I'm sorry to be a pain in the ** now but could someone please just write a little example. I'm very tired and have a huge hangover so i'm not at the peak of my mind right now.
Code: Select all
<?php
$string = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nulla diam.";
$wordarray = explode(" ", $string);
$numw = 6;
$outputstring = "";
for ($i=0;$i<$numw;$i++){
$outputstring .= $wordarray[$i]." ";
}
$outputstring .= "...";
echo $outputstring;
?>aerodromoi