Jump to content


Photo

skip first 100 words ...


  • Please log in to reply
1 reply to this topic

#1 devofash

devofash
  • Members
  • PipPipPip
  • Advanced Member
  • 81 posts

Posted 24 October 2006 - 08:00 PM

hello...

rite will get straight to the point. I got a paragraph in mysql field, I want to skip the first 100 words and display the rest of the paragraph on a page. how would I do this using php ?

hope someone will be able to help me out.

Thanks in advance.



#2 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 24 October 2006 - 08:29 PM

I have an example where I have an array that I wanted to do this for.

<?php

$text = "Whatever is in your DB field...";
$offset = "100"; //The amount of words to skip...

$newtext = skipWords($text, $offset);

function skipWords($text, $offset) {

			$words = explode(' ', $text);

//If the total amount of words are less than the offset, then just return the whole string

			if (count($words) > $offset) { 
				return implode(' ', array_slice($words, $offset));
			} else {
			return $text;
			}

		}

?>

Assuming you are pulling the record into an array, then you could do this.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users