SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    NJ
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Regular expressions

    Hi -can someone please tell me how I can do a search and replace on the following url using preg_replace

    index.php?section=admins_only&view=iscadmin_view.inc&bread_crumb=Insert%20Records&dir=/admins_only/&view_table=DISKS&resultpage=29

    I want to search for &resultpage= any number and replace it with nothing

    end result:
    index.php?section=admins_only&view=iscadmin_view.inc&bread_crumb=Insert%20Records&dir=/admins_only/&view_table=DISKS

  2. #2
    SitePoint Member
    Join Date
    Sep 2004
    Location
    tyrol
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi, have you tried this:

    $newString = preg_replace("/(&resultpage=[0-9]+)/","",$string);

    not tested, but should work

  3. #3
    simple tester McGruff's Avatar
    Join Date
    Sep 2003
    Location
    Glasgow
    Posts
    1,690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    NJ
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thx-

    $newString = preg_replace("/(&resultpage=[0-9]+)/","",$string);


    worked as designed....

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    NJ
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what if resultpage contains a minus number next to it..
    -67..I basically want to search for anthing after the = sign

  6. #6
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    NJ
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got it

    $temp_queryvars = preg_replace("/(&resultpage=.+[0-9]+)/","",$queryvars);

  7. #7
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What if resultpage is not the last query string param.

    Should you do a
    $temp_queryvars = preg_replace("/(&resultpage=[^&]+)/","",$queryvars);
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  8. #8
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Moved to a more appropriate forum. See Where should I post my thread? for details

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  9. #9
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    NJ
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What's wrong with this forum, this has to deal with php so what's the problem.. Learn how to read..

  10. #10
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    NJ
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes,

    $temp_queryvars = preg_replace("/(&resultpage=[^&]+)/","",$queryvars);

    is more appropriate.. thx

  11. #11
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by davide128
    What's wrong with this forum, this has to deal with php so what's the problem.. Learn how to read..
    Perhaps if you took your own advice you would read the thread I linked to and see that you posted in the wrong forum

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  12. #12
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    NJ
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok..I read the link..I see what you mean..sorry...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •