Page 1 of 1

preg_match pattern ?

Posted: Fri Sep 15, 2006 10:24 am
by Seb
Hello,

First, excuse for my english, i'm french ...

I want to use a regex to extract title of my page in the url.

My page could be : xxxxxxxxxx.html or xxxxxxxxx,2.html
I want to extract this part : xxxxxxxxxx ; ,2 is for navigation.

I try to use :

Code: Select all

preg_match(',^(.*)$,', $url_propre, $regs);
This is ok without navigation, but this don't work :

Code: Select all

preg_match(',^(.*)(\,[0-9]+)?$,', $url_propre, $regs);
The .html is deleted before.

I hope you can understand me ...

Have a nice day
Seb

Posted: Fri Sep 15, 2006 11:11 am
by Oren
If you know that the form is [file_name],[navigation].html then you can just use explode().

Also search for: mod_rewrite.

Posted: Fri Sep 15, 2006 11:43 am
by Seb
Hello Oren,

Thanks for this solution i don't have think to explode() ... it works !

My website is under spip gnu software, to call a page it use the name of the page without HTML (seo).

Just for information and to know how to do in regex, you know the regex solution ?

Nice day
Seb

Posted: Fri Sep 15, 2006 12:07 pm
by Oren

Code: Select all

$regex = '#(.+),([0-9]+)#i';