note 42405 added to function.strlen

From: Date: Sat, 15 May 2004 07:01:29 +0000
Subject: note 42405 added to function.strlen
Groups: php.notes 
Request: Send a blank email to php-notes+get-69625@lists.php.net to get a copy of this message
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); } ---- Manual Page -- http://www.php.net/manual/en/function.strlen.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+42405 Delete -- http://master.php.net/manage/user-notes.php?action=delete+42405&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+42405&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#69625) next »