note 13346 deleted from function.str-replace by philip

From: Date: Mon, 04 Feb 2002 12:49:26 +0000
Subject: note 13346 deleted from function.str-replace by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-26216@lists.php.net to get a copy of this message
I was kind of hoping to find a function where I can swap values in a string, but I couldn't find one, so I wronte one, here it is: function str_swap($swp1,$swp2,$str) { srand ((double) microtime() * 1000000); for($i=0;$i<32;$i++) $tmp .= rand(); str_replace($swp1,$tmp.$swp1.$tmp,$str); str_replace($swp2,$swp1,$str); str_replace($tmp.$swp1.$tmp,$swp2,$str); return $str; } EXAMPLE: $string = 'Bob went out with Sally.'; so str_swap('Bob','Sally',$string); would produce: 'Sally went out with Bob.

« previous php.notes (#26216) next »