Jump to content

Long Standing URL Problem


david64

Recommended Posts

Hi, my first post here. I've been programming PHP for some time, but never really had any need for help. However, I have had a long standing issue that I've never found a solution for, which I will detail here.

 

I have a loose framework for making sites, it consits of a few classes and I have also implemented a C-style multi-extend feature. It has a few different settings, the one I use most often is one that will run a method in my site class if it exists and include a template if it exists. For example if you load the page:

 

domain.ext/my-page

 

It will load the template _my-page.xsl and will run the method $site->html_my_page();

 

The template part is fine, however one problem is I might also have a page called:

 

domain.ext/my-page

 

and this would also run the method $site->html_my_page();

 

Because PHP uses the following reg. ex. [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]* to validate function names I cannot have a function name including "-".

 

Does anyone have any ideas as to what I can do?

 

I am very keen on the method outlined above of running a method according to the URL.

Link to comment
https://forums.phpfreaks.com/topic/123307-long-standing-url-problem/
Share on other sites

Simply convert illegal characters to underscores using either preg_replace, or str_replace ( if you only want to convert a few character to _ )

 

You would be limited by this, however, because my_page and my-page would return the same function... If you must, you could replace a dash with an odd string... xDASHx and name your function myxDASHxpage().

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.