di Agostino Zanutto
Snippet PHP: replace_substr
| Blog - Snippets |
Questo codice PHP è utile per sostituire o eliminare una sottostringa da una stringa...
Funziona sulla posizione, non sulla sottostringa.
codice php:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
/** * * (c)2011 SFS.it, All rights reserved * License: http://www.sfs.it/licenza-bsd44.html * Use and modify all you want just keep this comment. Thanks * **/ /** * function replace_substr * parameters: * $str: stringa originale * $startSubstr: posizione inizio stringa da sostituire / eliminare * $endStbstr: posizione finale stringa da sostituire / eliminare * $newSubstr: nuova stringa da sostituire * **/ function replace_substr($str,$startSubstr,$endSubstr,$newSubstr='') { return (($startSubstr>0)?substr($str,0,$startSubstr):'') . $newSubstr . ((strlen($str)>$endSubstr)?substr($str,$endSubstr):''); } |
Ultimo aggiornamento (Domenica 01 Maggio 2011 23:15)
