Re: URL Parsing...

From: Date: Mon, 26 Nov 2007 19:35:42 +0000
Subject: Re: URL Parsing...
References: 1 2 3 4 5 6 7  Groups: php.general 
Request: Send a blank email to php-general+get-265034@lists.php.net to get a copy of this message
Richard Heyes wrote: > Chris wrote: >> Richard Heyes wrote: >>>> well if you take a string (filename) and wish to change the end of >>>> it somone >>>> then I don't think str_replace() is the correct function. what's to >>>> say a script >>>> doesn't exist called 'my.cfm.php'? >>> >>> How does this: >>> >>> /\.cfm$/ >>> >>> take into account that? >> >> $ in regex's means 'end of string' - so it will only match .cfm at the >> very end of the string. > > Indeed, so how does the regex take into account ".cfm.php"? It doesn't. > If it doesn't have a .cfm extension, it won't match. because the question was "I want to replace the extension '.cfm' with '-meta.cfm', which I assumed meant the OP didn't want 'my.cfm.php' to become 'my-meta.cfm.php' and a str_replace('.cfm', '-meta.cfm', $foo) would not be correct in that situation. hopefully now the use of preg_replace() in my example makes sense. oh and I forget to add delimeters to the regexps in my examples, which was a stupid oversight. >

« previous php.general (#265034) next »