Re: [PHP] String manipulation with ereg_replace
From: "Ian LeBlanc" [EMAIL PROTECTED] 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] String manipulation with ereg_replace
On Thursday 22 February 2001 23:42, Simon Garner wrote: 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); ? simpler that "/([-_a-zA-Z0-9]+)\.gif/e" is "/([-\w]+)\.gif/e" -- Christian Reiniger LGDC Webmaster (http://sunsite.dk/lgdc/) Google results 1-10 of about 142,000,000 for e. Search took 0.18 seconds. - http://www.google.com/search?q=e -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]