preg_match pattern ?

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
Seb
Forum Newbie
Posts: 2
Joined: Fri Sep 15, 2006 10:16 am

preg_match pattern ?

Post 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
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

If you know that the form is [file_name],[navigation].html then you can just use explode().

Also search for: mod_rewrite.
Seb
Forum Newbie
Posts: 2
Joined: Fri Sep 15, 2006 10:16 am

Post 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
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Code: Select all

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