Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Apr 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Replace variable URL with regular expressions

    Hey guys. I need your help with regular expressions. First time dealing with them actually. I need to replace/remove a variable URL for my rss feed. Images are automatically formatted like this inside the img tags:

    https://fbexternal-a.akamaihd.net/safe_image.php?d=AQDZORAaPpbr5COr&w=154&h=154&url=http://example.com/image.jpg

    (Bold words are always like that, while the those in red vary)

    So, using preg_replace, I'd like remove the "https://fbexternal-a.akamaihd.net/safe_image.php?d=ALPHANUMERICVALUE&w=NUMERICVALUE&h=NUMERICVALUE&url=" string, while keeping "http://example.com/image.jpg" only.

    Thanks in advance for your help.

  • #2
    New to the CF scene
    Join Date
    Apr 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nevermind, a bit of digging and could do it myself!

    I will leave the solution here in case anyone might find it useful:

    preg_replace('@(https?://fbexternal-a.akamaihd.net/safe_image.php[?]d=?[a-zA-Z0-9]+[&]w=[0-9]+[&]h=[0-9]+[&]url=)@','',$link);

  • #3
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    851
    Thanks
    172
    Thanked 93 Times in 93 Posts
    PHP Code:
    $val="https://fbexternal-a.akamaihd.net/safe_image.php?d=AQDZORAaPpbr5COr&w=154&h=154&url=http://example.com/image.jpg";
    $val preg_replace("/.*(http:\/\/.*)/","$1",$val);
    print 
    $val;

    //http://example.com/image.jpg 

    LT
    "The greatest revenge is to accomplish what others say you cannot do."
    ~ Unknown

    I used to be indecisive, but now I'm not so sure.


  •  

    Posting Permissions

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