note 48202 modified in function.substr by aidan
| From: | aidan@php.net | Date: | Tue, 18 Jan 2005 15:40:06 +0000 |
| Subject: | note 48202 modified in function.substr by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-83554@lists.php.net to get a copy of this message | ||
Split $string after each $pos, by $space
Example: <?php spaceStr('1836254','-',3); ?>
Would return '183-625-4';
<?php
function spaceStr($string,$space,$pos)
{
$cpos=$pos;
while ($cpos<strlen($string))
{
$string=substr($string,0,$cpos).$space.substr($string,$cpos);
$cpos+=strlen($space)+$pos;
};
return $string;
}
?>
--was--
<?php
// split $string after each $pos, by $space
// example: spaceStr('1836254','-',3)
// return '183-625-4';
function spaceStr($string,$space,$pos)
{
$cpos=$pos;
while ($cpos<strlen($string))
{
$string=substr($string,0,$cpos).$space.substr($string,$cpos);
$cpos+=strlen($space)+$pos;
};
return $string;
}
?>
http://php.net/manual/en/function.substr.php