note 79700 added to function.substr

From: Date: Sun, 09 Dec 2007 05:48:33 +0000
Subject: note 79700 added to function.substr
Groups: php.notes 
Request: Send a blank email to php-notes+get-132968@lists.php.net to get a copy of this message
/*---English---*/ charAt: i needed the position of one char in a String, specifiying the number of occurrence of the char into the string. /* $string --> '12-12-12-23-34-45-5-6-70' $search --> '-' $occurence --> 5 */ function charat($string,$search,$occurence) { $occur = 0; for($i=0; $i<strlen($string); $i++) { if (substr ($string,$i,1) ==$search) { $occur++; if ($occur == $occurence) { return $i; } } } return -1; } echo charat('12-12-12-23-34-45-5-6-70','-',5); //14 echo charat('12-12-12-23-34-45-5-6-70','-',1); //2 echo charat('12-12-12-23-34-45-5-6-70','+',1); //-1 /* maybe the name of the function it is not accurrate, but works fine. */ /*---Espanol ---*/ Necesitaba una funcion que me dijera la posicion de un caracter en una cadena, como es posible que un caracter exista mas de una vez, el tercer parametro es para identificar el numero de ocurrencia que quiero que salga. Cristianlf ---- Server IP: 69.147.83.197 Probable Submitter: 201.216.151.174 ---- Manual Page -- http://www.php.net/manual/en/function.substr.php Edit -- https://master.php.net/note/edit/79700 Del: integrated -- https://master.php.net/note/delete/79700/integrated Del: useless -- https://master.php.net/note/delete/79700/useless Del: bad code -- https://master.php.net/note/delete/79700/bad+code Del: spam -- https://master.php.net/note/delete/79700/spam Del: non-english -- https://master.php.net/note/delete/79700/non-english Del: in docs -- https://master.php.net/note/delete/79700/in+docs Del: other reasons-- https://master.php.net/note/delete/79700 Reject -- https://master.php.net/note/reject/79700 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#132968) next »