This is a discussion on URL Parsing... within the PHP General forums, part of the PHP Programming Forums category; Hi, I'm working on redesigning the backend of the website for work. It was originally done in ColdFusion, but ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi,
I'm working on redesigning the backend of the website for work. It was originally done in ColdFusion, but I'm switching it over to PHP - probably going to transfer the website from where it's currently hosted to something a lot cheaper, too, hence the switching to PHP. Anyway. Because we are a manufacturing company, we have a few different lines of products. Currently, each different product line has it's own page (and own meta tags). The current set up has ColdFusion grabbing the current page from the URL stripping off the '.cfm' extension and adding '-meta.cfm' before including it in the header. I'm sure there is a way to do this in PHP, but I'm out of shape enough with using PHP that I can't remember, and I can't seem to find anything that will work for me. I just want to be able to pull whatever address is in the URL, get the file name, and go from there. Any ideas? Anything would be helpful. :) Thanks, Amanda |
|
|||
|
At 12:18 PM -0600 11/24/07, Amanda Loucks wrote:
>Hi, > >I'm working on redesigning the backend of the website for work. It was >originally done in ColdFusion, but I'm switching it over to PHP - probably >going to transfer the website from where it's currently hosted to something >a lot cheaper, too, hence the switching to PHP. Anyway. > >Because we are a manufacturing company, we have a few different lines of >products. Currently, each different product line has it's own page (and own >meta tags). The current set up has ColdFusion grabbing the current page >from the URL stripping off the '.cfm' extension and adding '-meta.cfm' >before including it in the header. > >I'm sure there is a way to do this in PHP, but I'm out of shape enough with >using PHP that I can't remember, and I can't seem to find anything that will >work for me. I just want to be able to pull whatever address is in the URL, >get the file name, and go from there. > >Any ideas? > >Anything would be helpful. :) > >Thanks, >Amanda From what I've read recently about meta tags, why? Most SE's have dropped their dependance on meta tags because of their abuse. Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com |
|
|||
|
Amanda Loucks wrote:
> Hi, > > I'm working on redesigning the backend of the website for work. It was > originally done in ColdFusion, but I'm switching it over to PHP - probably > going to transfer the website from where it's currently hosted to something > a lot cheaper, too, hence the switching to PHP. Anyway. > > Because we are a manufacturing company, we have a few different lines of > products. Currently, each different product line has it's own page (and own > meta tags). The current set up has ColdFusion grabbing the current page > from the URL stripping off the '.cfm' extension and adding '-meta.cfm' > before including it in the header. > > I'm sure there is a way to do this in PHP, but I'm out of shape enough with > using PHP that I can't remember, and I can't seem to find anything that will > work for me. I just want to be able to pull whatever address is in the URL, > get the file name, and go from there. > > Any ideas? one of these should give you something to go on: echo preg_replace('\.cfm$', '-meta.cfm', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)), "\n"; echo preg_replace('\.cfm$', '-meta.cfm', $_SERVER['PATH_TRANSLATED']), "\n"; echo preg_replace('\.cfm$', '-meta.cfm', $_SERVER['SCRIPT_FILENAME']), "\n"; > > Anything would be helpful. :) > > Thanks, > Amanda > |
|
|||
|
> one of these should give you something to go on:
> > echo preg_replace('\.cfm$', '-meta.cfm', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)), "\n"; > echo preg_replace('\.cfm$', '-meta.cfm', $_SERVER['PATH_TRANSLATED']), "\n"; > echo preg_replace('\.cfm$', '-meta.cfm', $_SERVER['SCRIPT_FILENAME']), "\n"; > >> Anything would be helpful. :) You don't need the overhead of PCRE, though it is the fastest to write, since it's already above for you... Or parse_url(). basename(__FILE__) will get you the filename. -- Richard Heyes +44 (0)800 0213 172 http://www.websupportsolutions.co.uk Knowledge Base and HelpDesk software that can cut the cost of online support |
|
|||
|
Richard Heyes wrote:
>> one of these should give you something to go on: >> >> echo preg_replace('\.cfm$', '-meta.cfm', >> parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)), "\n"; >> echo preg_replace('\.cfm$', '-meta.cfm', $_SERVER['PATH_TRANSLATED']), >> "\n"; >> echo preg_replace('\.cfm$', '-meta.cfm', $_SERVER['SCRIPT_FILENAME']), >> "\n"; >> >>> Anything would be helpful. :) > > You don't need the overhead of PCRE, though it is the fastest to write, > since it's already above for you... 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'? > > Or parse_url(). basename(__FILE__) will get you the filename. ah yes basename() - I forgot to put use that in the examples, good catch. > |
|
|||
|
> 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? -- Richard Heyes +44 (0)800 0213 172 http://www.websupportsolutions.co.uk Knowledge Base and HelpDesk software that can cut the cost of online support |
|
|||
|
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? WTF > |
|
|||
|
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. -- Postgresql & php tutorials http://www.designmagick.com/ |
|
|||
|
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. -- Richard Heyes +44 (0)800 0213 172 http://www.websupportsolutions.co.uk Knowledge Base and HelpDesk software that can cut the cost of online support |
|
|||
|
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. > |