SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Mar 2008
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Looking for regex tips for characters in a url

    What's the best way I can replace a random scale number on the end of a url so I can replace it with a different scale number?

    Original Urls:
    http://www.mydomain.com/picture/1/scale;240x350/
    http://www.mydomain.com/picture/2/scale;340x500/

    New Urls I Need:
    http://www.mydomain.com/picture/1/scale;179x263/
    http://www.mydomain.com/picture/2/scale;179x263/

    Here is what I came up with which is just a shot in the dark for me:

    PHP Code:
    $output preg_replace("/\/scale;.*/","/scale;179x263/",$url_string); 

  2. #2
    SitePoint Addict Beaumont's Avatar
    Join Date
    Mar 2005
    Posts
    219
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If the replacement is always going to be the same, there will never be another path segment after the scale part, etc. then something like that might be sufficient. FYI, you can use different delimiters (e.g. <>) so you don't have to escape the literal slash (/) in your pattern.

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2010
    Location
    Largo
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What about the brackets around the wildcard(.*) don't they have to be there?


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
  •