Zend - The PHP Company




Text

Add Code


sow() function  

Type: code fragment
Added by: Rival7
Entered: 01/08/2000
Last modified: 08/12/1999
Rating: - (fewer than 3 votes)
Views: 4890
The sow() function inserts a string into another string every given increment.


<?
/* Inserts a string into another string every increment */
function sow($string$insert$increment)
{
    
$insert_len strlen($insert);
    
$string_len strlen($string);
    
    
$string_len_ending $string_len intval$insert_len * ($string_len $increment)); 
    
    
$i $increment 1;
    
    while(
$string_len_ending $i)
    {
        
$string substr($string0$i) . $insert substr($string$i);
        
$i $i $increment $insert_len;
    
    }
    
    return 
$string;
}


?>


Usage Example


echo sow("hello world", "@", 3);
/* produces "hel@lo @wor@ld" */


Rate This Script





Search



This Category All Categories