0

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 :(

3
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by ahmedeqbal
0

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

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

"Your string" will return 11...

0

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

0

Here is code:

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

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... :(

Edited by ahmedeqbal: n/a

1

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);
?>
Votes + Comments
helpful reply...! nice guy
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.