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, working out the search and replace values

Discussion in 'PHP' started by sarahk, Jan 25, 2018.

  1. #1
    I've got a table with lots of content that assume the site and it's subdomains are on http://

    New content is being created with https:// and we don't want to alter the old records but if they're called we want to change the http to an https. Not all links, just the ones that link back to the site.

    so I've got
    upload_2018-1-26_20-23-59.png
    etc

    I could just set up an array with each subdomain but I figured it'd be more elegant to use preg_replace. What would I use as the search and replace values?
     
    Solved! View solution.
    sarahk, Jan 25, 2018 IP
  2. #2
    So you only want to replace http:// into https:// in some text? If all your subdomains are different (I mean subA, subB, etc.), I would use this one:

    $text=YOUR_TEXT_OR_SOME_STRING_WITH_DOMAINS_TO_BE_REPLACED;
    
    $text=preg_replace("/http:\/\/([A-Za-z0-9]+)\.domain\.com/", "https://$1.domain.com", $text);
    PHP:
     
    phpmillion, Jan 26, 2018 IP
    sarahk likes this.
  3. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #3
    Perfect, thank you!
     
    sarahk, Jan 26, 2018 IP
  4. gazimori

    gazimori Member

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #5
    hey i have an question , can be replaced a link from embbed page with javascript that using adnetworks nowdays and get only the link with echo $link; can be done these with php
     
    gazimori, Mar 27, 2019 IP
  5. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #5
    @gazimori - that would be quite straightforward.
     
    sarahk, Mar 28, 2019 IP
  6. gazimori

    gazimori Member

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #6
    not if it was a visit from the adzoned website, I do not know if you understand what I mean.

    get the link send the visits get the money you win i win , woila , :p
     
    gazimori, Mar 28, 2019 IP
  7. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #7
    You have a site that you want to use Javascript to change the links on. It's easy to get an array of all the links and to update them.
    You just have to own the site (or have users with a custom toolbar that you've written)
     
    sarahk, Mar 29, 2019 IP