URL Parsing...

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-24-2007
Amanda Loucks
 
Posts: n/a
Default URL Parsing...

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

Reply With Quote
  #2 (permalink)  
Old 11-24-2007
tedd
 
Posts: n/a
Default Re: [PHP] URL Parsing...

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
Reply With Quote
  #3 (permalink)  
Old 11-24-2007
Jochem Maas
 
Posts: n/a
Default Re: [PHP] URL Parsing...

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
>

Reply With Quote
  #4 (permalink)  
Old 11-25-2007
Richard Heyes
 
Posts: n/a
Default Re: [PHP] URL Parsing...

> 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
Reply With Quote
  #5 (permalink)  
Old 11-25-2007
Jochem Maas
 
Posts: n/a
Default Re: [PHP] URL Parsing...

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.

>

Reply With Quote
  #6 (permalink)  
Old 11-25-2007
Richard Heyes
 
Posts: n/a
Default Re: [PHP] URL Parsing...

> 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
Reply With Quote
  #7 (permalink)  
Old 11-25-2007
Jochem Maas
 
Posts: n/a
Default Re: [PHP] URL Parsing...

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

>

Reply With Quote
  #8 (permalink)  
Old 11-25-2007
Chris
 
Posts: n/a
Default Re: [PHP] URL Parsing...

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/
Reply With Quote
  #9 (permalink)  
Old 11-26-2007
Richard Heyes
 
Posts: n/a
Default Re: [PHP] URL Parsing...

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
Reply With Quote
  #10 (permalink)  
Old 11-26-2007
Jochem Maas
 
Posts: n/a
Default Re: [PHP] URL Parsing...

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.

>

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:11 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0