note 13346 added to function.str-replace.php

From: Date: Tue, 12 Jun 2001 20:06:54 +0000
Subject: note 13346 added to function.str-replace.php
Groups: php.notes 
Request: Send a blank email to php-notes+get-14420@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. http://www.php.net/manual/en/function.str-replace.php

« previous php.notes (#14420) next »