note 88798 deleted from function.strpos by levim

From: Date: Fri, 06 Dec 2013 16:34:14 +0000
Subject: note 88798 deleted from function.strpos by levim
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-197813@lists.php.net to get a copy of this message
Note Submitter: peterzuzek at gmail dot com ---- 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() ?>

« previous php.notes (#197813) next »