skip to Main Content

I need to insert only a HTTP in a list of links (10,000) that doesn’t have one, for exemple

<a href="nunm-press.com">

From

<a href="nunm-press.com"
to
<a href="http://nunm-press.com"

Suggestions?

I search for "str_replace replace only if doesn’t exist", found nothing.

2

Answers


  1. I dont exactly understand your question but if you are using php and you want to set http or https you can try this.

    $url = 'nunm-press.com';
    $parsed_url = parse_url($url);
    if (!isset($parsed_url['scheme'])) {
        $url = 'http://' . $url;
    }
    echo '<a href="' . $url . '">Link</a>';
    
    Login or Signup to reply.
  2. you can use str_replace function

    <?php
    $string='<a href="nunm-press.com">';
    $string_replace=str_replace('href="','href="http://',$string);
    echo $string.' >> '.$string_replace;
    ?>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search