here's a description of what i'm trying to do...
i want a variable to store the first hundred words of a website.
so for example, say i want to get the first 10 words of this text file
<!-- m --><a class="postlink" href="http://members.lycos.co.uk/sharpdust/Upload/blah.txt">http://members.lycos.co.uk/sharpdust/Upload/blah.txt</a><!-- m -->
and it will store that text as something like
$storedstring = "blah blah blah blah blah blah blah blah blah blah";
edit: i realize i just contradicted myself with the above post with the website/text file thing. i really want to know how to get the website more than the text file. but if someone knows how to do it with the text file, that will be a start for me.Maybe this thread helps?
<!-- m --><a class="postlink" href="http://www.htmlforums.com/showthread.php?s=&threadid=31560">http://www.htmlforums.com/showthread.ph ... adid=31560</a><!-- m -->
There somebody was trying to get the first 75 words of a text.. The code is maybe not perfect, but it'll get you started..Here's a function I use
function summary($string, $size){
$total = strlen($string);
if ($total <= $size) {
return $string;
} else {
while (preg_match("/[^ \.]/", substr($string, $size -1, 1))) {
$size++;
}
$sub_string = substr($string, 0, $size);
return $sub_string;
}
}
and to call it
$contenu = summary($content, 300);
300 being the number of characters you want to show.
I also have one that will spit out until you get to the first </p>
hth
i want a variable to store the first hundred words of a website.
so for example, say i want to get the first 10 words of this text file
<!-- m --><a class="postlink" href="http://members.lycos.co.uk/sharpdust/Upload/blah.txt">http://members.lycos.co.uk/sharpdust/Upload/blah.txt</a><!-- m -->
and it will store that text as something like
$storedstring = "blah blah blah blah blah blah blah blah blah blah";
edit: i realize i just contradicted myself with the above post with the website/text file thing. i really want to know how to get the website more than the text file. but if someone knows how to do it with the text file, that will be a start for me.Maybe this thread helps?
<!-- m --><a class="postlink" href="http://www.htmlforums.com/showthread.php?s=&threadid=31560">http://www.htmlforums.com/showthread.ph ... adid=31560</a><!-- m -->
There somebody was trying to get the first 75 words of a text.. The code is maybe not perfect, but it'll get you started..Here's a function I use
function summary($string, $size){
$total = strlen($string);
if ($total <= $size) {
return $string;
} else {
while (preg_match("/[^ \.]/", substr($string, $size -1, 1))) {
$size++;
}
$sub_string = substr($string, 0, $size);
return $sub_string;
}
}
and to call it
$contenu = summary($content, 300);
300 being the number of characters you want to show.
I also have one that will spit out until you get to the first </p>
hth