note 36809 added to ref.strings

From: Date: Thu, 23 Oct 2003 11:37:25 +0000
Subject: note 36809 added to ref.strings
Groups: php.notes 
Request: Send a blank email to php-notes+get-59163@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/ref.strings.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+36809 Delete -- http://master.php.net/manage/user-notes.php?action=delete+36809&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+36809&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#59163) next »