includes/functions.php
changeset 48 fc9762553a3c
parent 40 723bb7acf914
child 62 9dc4fded30e6
equal deleted inserted replaced
47:d6361ccbd2bd 48:fc9762553a3c
  2296     return true;
  2296     return true;
  2297   else
  2297   else
  2298     return false;
  2298     return false;
  2299 }
  2299 }
  2300 
  2300 
       
  2301 /**
       
  2302  * Replaces the FIRST given occurrence of needle within haystack with thread
       
  2303  * @param string Needle
       
  2304  * @param string Thread
       
  2305  * @param string Haystack
       
  2306  */
       
  2307 
       
  2308 function str_replace_once($needle, $thread, $haystack)
       
  2309 {
       
  2310   $needle_len = strlen($needle);
       
  2311   for ( $i = 0; $i < strlen($haystack); $i++ )
       
  2312   {
       
  2313     $test = substr($haystack, $i, $needle_len);
       
  2314     if ( $test == $needle )
       
  2315     {
       
  2316       // Got it!
       
  2317       $upto = substr($haystack, 0, $i);
       
  2318       $from = substr($haystack, ( $i + $needle_len ));
       
  2319       $new_haystack = "{$upto}{$thread}{$from}";
       
  2320       return $new_haystack;
       
  2321     }
       
  2322   }
       
  2323   return $haystack;
       
  2324 }
       
  2325 
  2301 //die('<pre>Original:  01010101010100101010100101010101011010'."\nProcessed: ".uncompress_bitfield(compress_bitfield('01010101010100101010100101010101011010')).'</pre>');
  2326 //die('<pre>Original:  01010101010100101010100101010101011010'."\nProcessed: ".uncompress_bitfield(compress_bitfield('01010101010100101010100101010101011010')).'</pre>');
  2302 
  2327 
  2303 ?>
  2328 ?>