Hi, I need a PHP developer who could write me some string manipulation functions. Taking a string, finding a substring based on opening and closing delimiters. Extractng the substring and then returning one element randomly from a delimited substring i.e "This is {my|your} string" Results of the main function call could be: "This is my string" or "This is your string" The original string may contain mutliple { } sections Thanks, J
I'd like to get in touch with you, I can do this kind of work easily. What's the best way to get in contact?
Here it is: <?php function get_random_string($string) { $result = $string; if (preg_match_all("/\{(.*?)}/si", $string, $match, PREG_SET_ORDER)) { for ($i = 0; $i < count($match); $i++) { $words = explode("|", $match[$i][1]); $random = $words[array_rand($words)]; $result = str_replace($match[$i][0], $random, $result); } } return $result; } ?> PHP: Sample usage: <?php echo get_random_string("I'm {robot|human}. I'm from {earth|venus}."); ?> PHP: