note 61836 added to function.substr
| From: | shadzar at osu1 dot php dot net | Date: | Mon, 13 Feb 2006 13:21:01 +0000 |
| Subject: | note 61836 added to function.substr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-103621@lists.php.net to get a copy of this message | ||
a function to read in a file and split the string into its individual characters and display them as
images for a webcounter.
can be used anywhere you need to split a string where a seperator is not present and versions where
the str_split() function is also not present.
<?php
//start counter
$filename = "counter_file.txt";
$pathtoiamges = "http://www.yoursite.com/counter/";//where
is your iamges
$extension = ".gif";//what filetype are your images in
//--------------do not change below this line-------------------
$counter=file_get_contents($filename);
$counter++;
$count=$counter;
$current=0;
$visit=array("");//array to hold individual characters
//split string into individual characters
//same as str_split($str) in PHP5
while (strlen($count)>0)
{
$current++;
$visit[$current]=substr($count,0,1);//get current digit
$count=substr($count,1,strlen($count));//reduce number string to remove last stored digit
}
//display images of digits
foreach ($visit as $vis)
{
if ($vis!=""){echo "<img src=\"". $pathtoimages . $vis . .$extension .
"\">";}
}
$list = fopen($filename, "w+");
fwrite($list, $counter);
fclose($list);
//end counter
?>
requires a file to store the counter and 10 images to represent the digits (0-9) if used as a
counter.
----
Server IP: 64.71.164.2
Probable Submitter: 71.71.72.4
----
Manual Page -- http://www.php.net/manual/en/function.substr.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+61836
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61836&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61836&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61836&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61836&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61836&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61836&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61836&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+61836&report=yes
Search -- http://master.php.net/manage/user-notes.php