Hello Friends,

I need your help...!

i want to create one function...!

if string has total Character's '160' or 'Less' then 160 ? I'll get just '1' in result...!

if string Character limit 'double' (160+160) = 320? But not Less then 160? I'll get '2' in result...!
same triple limit 640 not Less then 320. so I'll get '3' in result.

Please explain logic with code..

Thanks :(

Member Avatar for P0lT10n

If you want to know the lenght of a string, use

strlen("your string") or strlen($variable)

"Your string" will return 11...

yes, with 'strlen' just im able to count total words...! but how to create real world function related with me task? Please, help anybody. :(

Here is code:

<?
	function mapString($str,$ch)
	{	
		return floor(strlen($str)/$ch);
	}
	$text = "your text goes here.";
	echo mapString($text,160);
?>

wow, nice dear...! thanks for code...!
but how i count? if string has less then 160 character return 1, if string 320 character or not less then 160 return 2....! because following code return 0 if character less then 160..! please... :(

This comment will help u to understand.

<?
	function mapString($str,$ch)
	{	
		$string_length = strlen($str); //e.g. length is 162
		
		if(strlen($str) < $ch) // if length is less than 160 return 1
		{	return 1; } 
		
		$ratio = $string_length/$ch ; // so ratio will be 162/160 => 1.33
		return floor($ratio); // round 1.33 to 1
	}
	$text = "your text goes here.";
	echo mapString($text,160);
?>
commented: helpful reply...! nice guy +2

thanks dear...! really helpful tip...!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.