Friday, August 1, 2008

Word Limit Code

$strScentence="My Name is Ritesh Kumar Sahu";
$limit=4; // number or words

$strLimit=limitScentence($strScentence,$limit);
echo $strLimit;





/*------------ function to limit the scentence -------------*/
function limitScentence($strScentence,$limit)
{

$arrWords=preg_split("/\s+/", $strScentence);
if(count($arrWords)<$limit)
{
return $strScentence;
}
$strLimitScentence="";
for($i=0;$i<$limit;$i++)
{
$strLimitScentence.=$arrWords[$i]." ";
}
$strLimitScentence=substr($strLimitScentence,0,strlen($strLimitScentence)-1);
return $strLimitScentence;
}
/*------------- Created By Ritesh Kumar Sahu-------------*/


?>

5 comments:

  1. Nice code, it saves lots of my time

    Ashwani Pradhan
    SE(Internal projects)
    Synapse India

    ReplyDelete
  2. Hi Ritesh,
    This is with reference to your candidature. We are delighted to inform that you have been short listed for the post of Software Engineer.

    You are requested to come for the interview. The details are mentioned below:



    Venue: H-23, Sector-63, Noida, Behind Bikanerwala

    Time- 7:30 PM /08.09.08

    Contact Person: Sarika

    ReplyDelete