Jump to content

[SOLVED] word counter


corillo181

Recommended Posts

how do i limit a paragraph to a set number. like if i got a strory and i only want 15 words to show how would i do it?

 

i got it stared but ran out of idea.

 

<?php
function shortBio($id,$length){
	$query="SELECT bio FROM tra_artist WHERE artist_id='$id'";
	$result=$this->db->query($query);
	$txt = $this->db->fetch_array($result);
	$newtxt =explode(" ",$txt['bio']);
	$count = count($newtxt);

}

?>

Link to comment
https://forums.phpfreaks.com/topic/72229-solved-word-counter/
Share on other sites

<?php

$newtxt =explode(" ",$txt['bio']);

for ($i=0; $i<15; $i++){
   echo $newtxt[$i].' ';
}

?>

 

There could be a better way...but that works.

 

Teng84 - They didn't say they wanted 15 words per LINE, they want 15 words total. At least from what I understand.

Link to comment
https://forums.phpfreaks.com/topic/72229-solved-word-counter/#findComment-364219
Share on other sites

<?php

$newtxt =explode(" ",$txt['bio']);

for ($i=0; $i<15; $i++){
   echo $newtxt[$i].' ';
}

?>

 

There could be a better way...but that works.

 

Teng84 - They didn't say they wanted 15 words per LINE, they want 15 words total. At least from what I understand.

 

ohh yah but this might be usefull

 

look you dont know how long each words ;D

 

Link to comment
https://forums.phpfreaks.com/topic/72229-solved-word-counter/#findComment-364222
Share on other sites

<?
function shortBio($id,$length){
	$query="SELECT bio FROM tra_artist WHERE artist_id='$id'";
	$result=$this->db->query($query);
	$txt = $this->db->fetch_array($result);
	$newtxt =explode(" ",$txt['bio']);
	if (count($newtxt)<15){
		return $txt['bio'];}
	else{
		for($x=0;$x<15;$x++){
			$words .= $newtxt[$x];
		}
	return $words;
	}

}

?>

;D

Link to comment
https://forums.phpfreaks.com/topic/72229-solved-word-counter/#findComment-364224
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.