1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

preg_replace pattern

Discussion in 'PHP' started by baris22, May 15, 2010.

  1. #1
    hello all,
    i need to match this.

    
    http://rapidshare.com/files/331947036/hjs.zip 
    
    PHP:
    (There is a space after zip)

    and change in to

    
    File is on rapidshare!
    
    PHP:
    First part "http://rapidshare.com/" is always same but rest of it will be different for every link.

    this is my code but id does not work.
    SEMrush
    
    $fullpage = preg_replace("#http://rapidshare.com/(.+?)\ #i", "File is on rapidshare! ", $fullpage);
    
    PHP:
     
    baris22, May 15, 2010 IP
    SEMrush
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    But you would want "File is on rapidshare" to be a new link ?
     
    MyVodaFone, May 15, 2010 IP
  3. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #3
    baris22, May 15, 2010 IP
  4. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #4
    The issue with your pattern is that you need to escape the the dot character -> . with a backslash as its considered a special character.

    $fullpage = preg_replace('~http://rapidshare\.com/files/[^ ]+~i', 'File is on rapidshare!', trim($fullpage));
    PHP:
     
    danx10, May 15, 2010 IP
    baris22 likes this.
  5. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #5
    I do not know why but it turned into

    
    File is on rapidshare!js.zip 
    
    PHP:
    I changed it into this and worked perfect. thanks alot.

    
    $fullpage = preg_replace('~http://rapidshare\.com/files/[\w]+/.+?\s~i', 'File is on rapidshare!', $fullpage);
    
    PHP:
     
    baris22, May 15, 2010 IP