note 73184 added to function.substr
| From: | neojoda at neojoda dot no-ip dot org | Date: | Mon, 12 Feb 2007 17:00:18 +0000 |
| Subject: | note 73184 added to function.substr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-123284@lists.php.net to get a copy of this message | ||
La anterior funcion "piece" funcionaba únicamente si el delimitador era de un caracter.
Aquà la misma función + una de apoyo parecida a la str_split , pero el delimitador que se le
pasa a la funcion "piece", puede ser un caracter o un conjunto de caracteres.
function str_splitPiece($entrada,$delim){
$lenStr=strlen($entrada);
$lenDelim=strlen($delim);
$arrayReturned = array();
$firts = substr($delim,0,1);
for ($i = 0; $i < $lenStr; $i++) {
if ($entrada[$i]==$firts){
$aux=substr($entrada,$i,$lenDelim);
if ($aux == $delim){
$arrayReturned[] = $aux;
$i = ($i+$lenDelim)-1;
}else{
$arrayReturned[] = $entrada[$i];
}
}else{
$arrayReturned[] = $entrada[$i];
}
}
return $arrayReturned;
}
function piece($entrada,$delim,$num){
$sortida="";
$cont = 1;
$find = 0;
$cadena = str_splitPiece($entrada,$delim);
foreach ($cadena as $key=>$value){
if ($value == $delim){
if ($cont==$num){
$find=1;
}else{
$cont++;
$sortida="";
}
}else{
if ($find!=1){
$sortida = $sortida.$value;
}
}
}
return $sortida;
}
----
Server IP: 130.206.1.5
Probable Submitter: 195.235.93.131 (proxied: 10.95.105.235)
----
Manual Page -- http://www.php.net/manual/en/function.substr.php
Edit -- https://master.php.net/note/edit/73184
Del: integrated -- https://master.php.net/note/delete/73184/integrated
Del: useless -- https://master.php.net/note/delete/73184/useless
Del: bad code -- https://master.php.net/note/delete/73184/bad+code
Del: spam -- https://master.php.net/note/delete/73184/spam
Del: non-english -- https://master.php.net/note/delete/73184/non-english
Del: in docs -- https://master.php.net/note/delete/73184/in+docs
Del: other reasons-- https://master.php.net/note/delete/73184
Reject -- https://master.php.net/note/reject/73184
Search -- https://master.php.net/manage/user-notes.php