note 36810 deleted from function.preg-replace by cmb
| From: | cmb@php.net | Date: | Sun, 22 Sep 2019 07:58:04 +0000 |
| Subject: | note 36810 deleted from function.preg-replace by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212296@lists.php.net to get a copy of this message | ||
Note Submitter: thewolf at pixelcarnage dot com
----
I got sick of trying to replace just a word, so I decided I would write my own string replacement
code. When that code because far to big and a little faulty I decided to use a simple preg_replace:
<?php
/**
* Written by Rowan Lewis
* $search(string), the string to be searched for
* $replace(string), the string to replace $search
* $subject(string), the string to be searched in
*/
function word_replace($search, $replace, $subject) {
return preg_replace('/[a-zA-Z]+/e', '\'\0\' == \'' . $search
. '\' ? \'' . $replace . '\': \'\0\';', $subject);
}
?>
I hope that this code helpes someone!