note 25884 modified in function.str-replace by bjori

From: Date: Wed, 28 Mar 2007 13:53:40 +0000
Subject: note 25884 modified in function.str-replace by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-124882@lists.php.net to get a copy of this message
To use one or two arrays in str_replace, this appears to be the correct format: <?php str_replace(array('1st_current_needle_element', '2nd', '3rd'), array('1st_new_needle_element', '2nd', '3rd'), $haystack) ?> Example of a single array, which simply removes the characters in the first array: <?php $text=str_replace(array('<', '>', '\\', '/', '='), "", $text); ?> This will delete the chars: < > \ / = It could also be done by first defining the array(s), like this: <?php $targetChars=array('<', '>', '\\', '/', '='); $text=str_replace($targetChars, "", $text); ?> --was-- To use one or two arrays in str_replace, this appears to be the correct format: <?php str_replace(array('1st_current_needle_element', '2nd, '3rd'), array('1st_new_needle_element', '2nd', '3rd'), $haystack) ?> Example of a single array, which simply removes the characters in the first array: <?php $text=str_replace(array('<', '>', '\\', '/', '='), "", $text); ?> This will delete the chars: < > \ / = It could also be done by first defining the array(s), like this: <?php $targetChars=array('<', '>', '\\', '/', '='); $text=str_replace($targetChars, "", $text); ?> http://php.net/manual/en/function.str-replace.php

« previous php.notes (#124882) next »