Re: String manipulation with ereg_replace

From: Date: Thu, 22 Feb 2001 22:42:17 +0000
Subject: Re: String manipulation with ereg_replace
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-41226@lists.php.net to get a copy of this message
From: "Ian LeBlanc" <Ian@rask.com> > > I am working on a site that has over 1000 pages and all the images need to > be made lower case in the HTML. > Here is what I have so far. Please someone tell me what I am doing wrong. > > > $contents="<img src=ThisOneReallyNeedsToBeAllLowercase.gif > alt=ThisOneReallyNeedsToBeAllLowercase.gif>"; > > $contents = EREG_REPLACE("([-_a-zA-Z0-9]+).gif",strtolower("\\0"),$contents); > > > Output of $contents needs to equal > <img src=thisonereallyneedstobealllowercase.gif > alt=thisonereallyneedstobealllowercase.gif> > > You need to use preg_replace which supports evaluating PHP code for the replacement. To use preg functions you need to have compiled PHP with PCRE (Perl Compatible Regular Expression) support. http://www.php.net/manual/function.preg-replace.php3 This should do the trick (untested!): <? $contents = "<img src=ThisOneReallyNeedsToBeAllLowercase.gif alt=ThisOneReallyNeedsToBeAllLowercase.gif>"; $contents = preg_replace("/([-_a-zA-Z0-9]+)\.gif/e", "strtolower('\\1') . '.gif'", $contents); ?> Cheers Simon Garner

« previous php.general (#41226) next »