/    Sign up×
Community /Pin to ProfileBookmark

Folks,

I’m afraid the following preg_replace is not doing the job. Can you think of a better one ?
Actually, if you can come-up with one that does the following then I’d appreciate it:

  • 1. Replace ‘https://’ with: ‘http://mydomain.com‘.

  • 2. Replace ‘http://’ with: ‘http://mydomain.com‘.

  • 3. Replace ‘www.’ with: ‘http://mydomain.com‘.

  • 4. Replace all subdomains and sub sub domains etc. with: ‘http://mydomain.com‘.
    eg1. Replace ‘mail.domain.com’ with ‘http://mydomain.com‘.
    eg2. Replace ‘ny.mail.domain.com’ with ‘http://mydomain.com‘.
    eg3. Replace ‘europe.spain.mail.domain.com’ with ‘http://mydomain.com‘.
    eg4. Replace ‘west.europe.deutchland.mail.domain.com’ with ‘http://mydomain.com‘.
    And so on. You get the picture.
  • I tried the following code but it’s not working. Instead of replacing things with ‘http://mydomain.com‘ it is replacing with: ‘%24url//’. And that is a big No! No!

    [code]

    <?php
    $url = “http://google.com”;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, “$url”);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, 5);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    $result = curl_exec($ch);
    curl_close($ch);
    $result = preg_replace(“#(<s*as+[^>]*hrefs*=s*[“‘])(?!http)([^”‘>]+)([“‘>]+)#”,’$1http://$url/$2$3’, $result);
    echo $result
    ?>

    [/code]

    Cheers!

    to post a comment
    PHP

    0Be the first to comment 😎

    ×

    Success!

    Help @uniqueideaman spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.19,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...