edit get text and limit it by word count

I don’t know how to write PHP so I was wondering if someone could help me edit a PHP file.
I have this line of code that gets the introtext for an article:

<?php if($item->params->get('genericItemIntroText')): ?>
		  <!-- Item introtext -->
		  <div class="genericItemIntroText">
		  	<?php echo $item->introtext; ?>
		  </div>
		  <?php endif; ?>

It gets all the text for the entire article. Can I rewrite this to limit the text by a certain number of words (like 30 words)
THANKS SO MUCH FOR YOUR HELP!!

Hi there,

Not tested it yet, but try this:
[php]$text = “this is some text”;
$maxwords = 3;
$words = array_splice(explode(" ",$text),$maxwords+1);
echo "Snippet: “.implode(” ",$words);
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service