Skip to content

Instantly share code, notes, and snippets.

@dgmike
Created May 10, 2010 23:01
Show Gist options
  • Select an option

  • Save dgmike/396658 to your computer and use it in GitHub Desktop.

Select an option

Save dgmike/396658 to your computer and use it in GitHub Desktop.
<?php
/**
* Exemplo de uso:
*
* echo change_str(',', '|', 'a,b,c,d,e', 3);
* >>> 'a,b,c,d|e'
*/
function change_str($str, $replacer, $string, $pos)
{
$y=explode($str, $string, $pos+2);
if (isset($y[$pos+1])){
$y[$pos]=$y[$pos].$replacer.$y[$pos+1];
array_pop($y);
}
$z=implode($str, $y);
return $z;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment