S
S
SergeyMakhnov2020-02-08 00:56:46
JavaScript
SergeyMakhnov, 2020-02-08 00:56:46

How to use parse_url for string with multiple urls?

Hello.
There is a string containing several urls in the format:

https://example.ru/example/ https://example1.ru/example1 https://example2.ru/example2

And so on, the url in the line can be as many as you like, there is with https, there is http, different in general.

It is necessary to convert them to the form
example.ru example1.ru example2.ru

I tried to do this using the function parse_url($url, PHP_URL_HOST);, but it only converts the very first url in the line, i.e. it turns out
example.ru https://example1.ru/example1 https://example2.ru/example2


Is there any way to make parse_url process all strings? Tried to google the solution using preg_replace but didn't find any working one.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stockholm Syndrome, 2019-05-26
@archi_kud

save it to a variable

const handler = () => this.changeValue(textfield, target);
window.addEventListener('click', handler);
window.removeEventListener('click', handler);

E
Eugene, 2020-02-08
@SergeyMakhnov

<?php
$text = 'https://example.ru/example/ https://example1.ru/example1 https://example2.ru/example2';
$array = preg_split('~\s+~', $text);
$urls = array_map(function ($split) {
    return parse_url($split, PHP_URL_HOST);
}, $array);
var_dump($urls);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question