php preg_replace help

djalam

Member
Messages
89
Reaction score
2
Points
8
I'm currently working on a paging script i got from online, everything works good and all so i wanted to make it into a pretty link for example

Before
http://www.mysite.com/index.php?page=2

After(w/ pretty links)
http://www.mysite.com/page/2/

I have already corrected the .htaccess to work with the link so its good to go, only thing i need help in is taking the Before link and convert it pretty link format, i know it can be done using pregreplace but i'm still new to this so still confused as to how to do this (and yes i google'd), just need a
PHP:
function blah($rawlink) {
//code to convert and return into pretty link.
}

Thanx in advance to any/and everyone
 
Last edited:

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
http://www.mysite.com/index.php?page=2

Is this part always the same? Or can 'page' and 'index.php' vary?
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
function blah($rawlink) {

$pattern = '/\/index\.php\?page=(\d+)$/' ;

return preg_replace( $pattern , '/page/$1' , $rawlink );


}
 

djalam

Member
Messages
89
Reaction score
2
Points
8
hey descalzo, thanx for helping out
I tried the function u provided above
and it still echo same index.php?page=2
 

djalam

Member
Messages
89
Reaction score
2
Points
8
O I just got it, thanx descalzo. lol now i'm trying to figure outbHow do I give you credits?
I pressed on the reputaion button for your post hope that does it.
 
Last edited:
Top