Home  |  Linux  | Mysql  | PHP  | XML
From:nick@NOSPAM.pitchinteractive.com Date:Mon Oct  6 17:12:18 2008
Subject:note 86177 added to function.str-replace
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;
	}
}
?>
----
Server IP: 64.71.164.2
Probable Submitter: 75.100.120.26
----
Manual Page -- http://www.php.net/manual/en/function.str-replace.php
Edit        -- https://master.php.net/note/edit/86177
Del: integrated  -- https://master.php.net/note/delete/86177/integrated
Del: useless     -- https://master.php.net/note/delete/86177/useless
Del: bad code    -- https://master.php.net/note/delete/86177/bad+code
Del: spam        -- https://master.php.net/note/delete/86177/spam
Del: non-english -- https://master.php.net/note/delete/86177/non-english
Del: in docs     -- https://master.php.net/note/delete/86177/in+docs
Del: other reasons-- https://master.php.net/note/delete/86177
Reject      -- https://master.php.net/note/reject/86177
Search      -- https://master.php.net/manage/user-notes.php

Navigate in group php.notes at sever news.php.net
Previous Next




  
© No Copyright
You are free to use Anything
Site Maintained by PHP Developer
Powered By PHP Consultants