+ Reply to Thread
Results 1 to 7 of 7

Thread: php preg_replace help

  1. #1
    djalam is offline x10Hosting Member djalam is an unknown quantity at this point
    Join Date
    Jan 2008
    Posts
    71

    Question php preg_replace help

    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 Code:
    function blah($rawlink) {
    //code to convert and return into pretty link.

    Thanx in advance to any/and everyone
    Last edited by djalam; 04-22-2010 at 04:36 PM.

  2. #2
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: php preg_replace help

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

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

  3. #3
    djalam is offline x10Hosting Member djalam is an unknown quantity at this point
    Join Date
    Jan 2008
    Posts
    71

    Re: php preg_replace help

    yeah its always the same only thing that changes is the number '2' and 'page'
    well...actually i think page might also change to something like
    section=car (http://www.mysite.com/index.php?section=car -> http://www.mysite.com/section/car/)
    Last edited by djalam; 04-22-2010 at 04:49 PM.

  4. #4
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: php preg_replace help

    function blah($rawlink) {

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

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


    }
    Nothing is always absolutely so.

  5. #5
    djalam is offline x10Hosting Member djalam is an unknown quantity at this point
    Join Date
    Jan 2008
    Posts
    71

    Re: php preg_replace help

    hey descalzo, thanx for helping out
    I tried the function u provided above
    and it still echo same index.php?page=2

  6. #6
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: php preg_replace help

    What is the URL you are feeding it?
    Nothing is always absolutely so.

  7. #7
    djalam is offline x10Hosting Member djalam is an unknown quantity at this point
    Join Date
    Jan 2008
    Posts
    71

    Re: php preg_replace help

    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 by djalam; 04-22-2010 at 05:40 PM.

+ Reply to Thread

Similar Threads

  1. Help with PHP - preg_replace()
    By callumacrae in forum Programming Help
    Replies: 12
    Last Post: 04-17-2010, 10:59 AM
  2. PHP preg_replace() error?
    By colacadstink in forum Free Hosting
    Replies: 1
    Last Post: 03-06-2008, 01:09 PM
  3. preg_replace
    By YodaOfDarkness in forum Free Hosting
    Replies: 6
    Last Post: 10-09-2007, 01:48 PM
  4. New PHP and preg_replace
    By demonguard in forum Free Hosting
    Replies: 2
    Last Post: 09-25-2007, 08:30 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers