note 86177 deleted from function.str-replace by cmb

From: Date: Sun, 15 Sep 2019 14:51:06 +0000
Subject: note 86177 deleted from function.str-replace by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-212217@lists.php.net to get a copy of this message
Note Submitter: nick at NOSPAM dot pitchinteractive dot com ---- I tried max at efoxdesigns dot com solution for str_replace_once but it didn't work quite right so I came up with this solution (all params must be strings): <?php function str_replace_once($search, $replace, $subject) { $firstChar = strpos($subject, $search); if($firstChar !== false) { $beforeStr = substr($subject,0,$firstChar); $afterStr = substr($subject, $firstChar + strlen($search)); return $beforeStr.$replace.$afterStr; } else { return $subject; } } ?>

« previous php.notes (#212217) next »