note 42405 deleted from function.strlen by nlopess
| From: | nlopess@php.net | Date: | Mon, 17 May 2004 13:05:19 +0000 |
| Subject: | note 42405 deleted from function.strlen by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-69710@lists.php.net to get a copy of this message | ||
Note Submitter: Ruben Barkow
----
here is a function to get the lenth of a string without using GDlib:
function pixellen($str){ // gets the approximate length of a string in pixel
// it is calculated for the font arial and fontsize 12,
// but it works as a measurement for all sizes and most fonts have similar proportions
$b[1]="ilI:;,.!'";
$b[2]="j[]";
$b[3]='frt-"/(){}1 ';
$b[4]="kJ";
$b[5]="abcdeghnopqsuvxyzEFLPT§$=?+234567890äöü";
$b[6]="BCDHKNRSUXZ_&ßÜ";
$b[7]="mAGMOQVYÄÖ";
$b[8]="";
$b[9]="w%";
$b[10]="";
$b[11]="W";
for($i=0; $i<strlen($str); $i++): // for each letter
$found=0;
for($j=1; $j<=11; $j++):
if ( strstr($b[$j], $str[$i])) $pixel=$pixel+$j;
$found=1;
continue;
endfor;
if ($found==0) $pixel+=5; // all other characters
endfor;
# change the factor to fit your font or just use the result as a measure
$factor=1.5;
return ($pixel*$factor);
}