F
F
First Name2017-08-24 16:06:12
1C-Bitrix
First Name, 2017-08-24 16:06:12

A valid protocol is not being made in the URI, why?

Good day to all.
There is a list of links, some of them have incorrect protocols (http:/, https:/).
You need to replace it with normal ones (add a second slash).
I upload a file with yurls, go through the array, check and replace, but for some reason it doesn’t work: C

foreach ($get_csv as $url) { 
    if(!strpos($url[0], '://')){
        $url[0]= str_replace(':/', '://', $url[0]);
    }
}

There is an error in the original array
tTx-ognl6pM.jpg
. After processing, it still remains: С
yLN6v8R2-XE.jpg
Tell me, please, what is the catch ..
Thank you in advance for the answers.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
A
Ainur Valiev, 2019-05-01
@vaajnur

the standard unloading module is a complete crap, I advise the export module from Acrit.

A
Anton, 2019-05-02
@anton99zel

And I will advise you to create your own upload file, because the standard one, as they wrote above, is crap.
Yours is written in a couple of hours.

D
Dmitry, 2017-08-24
@maxxtweek

1. You cannot check the result of the stripos function for negativity in this way. It can return 0, which will mean that the substring was found on a null character, and you will end up with "unable to find"
2. In fact, you must return $url back to $get_csv in the desired key, i.e. it should be

foreach ($get_csv as $k => $url) { 
    if(!strpos($url[0], '://')){
        $get_csv[$k][0] = str_replace(':/', '://', $url[0]);
    }
}

A
Alexander Aksentiev, 2017-08-24
@Sanasol

if(!strpos($url[0], '://')){
Warning
This function can return either boolean FALSE or a non-boolean value that casts to FALSE. See Boolean type for more information. Use the === operator to test the value returned by this function.

I
Ilya, 2017-08-24
Hrebet @hrebet

$get_csv = [
    'http://vk.com',
    'https:/vk.com',
];

foreach ($get_csv as &$url) { 
    if(strpos($url, '://') === false) {
        $url = str_replace(':/', '://', $url);
    }
}

print_r($get_csv);

Array
(
    [0] => http://vk.com
    [1] => https://vk.com
)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question