note 36810 added to function.str-replace

From: Date: Thu, 23 Oct 2003 11:38:58 +0000
Subject: note 36810 added to function.str-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-59164@lists.php.net to get a copy of this message
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: function word_replace($search, $replace, $subject) { /*------------------------------------------------------- Written by Rowan Lewis of PixelCarnage.com --------------------------------------------------------- $search(string), the string to be searched for $replace(string), the string to replace $search $subject(string), the string to be searched in -------------------------------------------------------*/ return preg_replace('/[a-zA-Z]+/e', '\'\0\' == \'' . $search . '\' ? \'' . $replace . '\': \'\0\';', $subject); } I hope that this code helpes someone! ---- Manual Page -- http://www.php.net/manual/en/function.str-replace.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+36810 Delete -- http://master.php.net/manage/user-notes.php?action=delete+36810&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+36810&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#59164) next »