note 88798 added to function.strpos
| From: | peterzuzekatgmaildotcom at osu1 dot php dot net | Date: | Sun, 08 Feb 2009 19:01:05 +0000 |
| Subject: | note 88798 added to function.strpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-150386@lists.php.net to get a copy of this message | ||
A function that return the first occurance of a number in a string, if anyone needs it.
Translation/prevod:
Funkcija, ki vraÄa pozicijo prve Å¡tevilke v besedi, Äe jo kdo potrebuje.
<?php
function firstNumPos($str) {
$poses = array(); // will be storing positions of the numbers
for($i = 0; $i < 10; ++$i) { // cycle through numbers
if(($a = strpos($str, (string)$i)) !== false) {
$poses[] = $a; // append the position of
// the first occurance of the number
}
}
if(isset($poses[0])) { // if array not empty
sort($poses); // sort to get the lowest one on the 'bottom'
return $poses[0]; // and return it
}
return false; // otherwise return false
} // firstNumPos()
?>
----
Server IP: 213.250.2.28
Probable Submitter: 89.212.132.190
----
Manual Page -- http://www.php.net/manual/en/function.strpos.php
Edit -- https://master.php.net/note/edit/88798
Del: integrated -- https://master.php.net/note/delete/88798/integrated
Del: useless -- https://master.php.net/note/delete/88798/useless
Del: bad code -- https://master.php.net/note/delete/88798/bad+code
Del: spam -- https://master.php.net/note/delete/88798/spam
Del: non-english -- https://master.php.net/note/delete/88798/non-english
Del: in docs -- https://master.php.net/note/delete/88798/in+docs
Del: other reasons-- https://master.php.net/note/delete/88798
Reject -- https://master.php.net/note/reject/88798
Search -- https://master.php.net/manage/user-notes.php