W
W
weranda2018-02-04 18:02:25
PHP
weranda, 2018-02-04 18:02:25

How to exclude a substring from a string in PHP?

The following line comes in response from API.YouTube:

Описание видео\nПодробное описание работы: https://site.ru/xxx/ccc/

I somehow need to split the string by "\n", merge into one and exclude everything that comes after http.* It should turn out:
Описание видео. Подробное описание работы
Something I'm dumb. And str_replace and preg_replace and explode tried...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
entermix, 2018-02-04
@weranda

.*:\s
https://regex101.com/r/LCgdTY/4

$text = 'Описание видео\nПодробное описание работы: https://site.ru/xxx/ccc/';
preg_match('/.*:\s/', $text, $matches);
$result = trim(str_replace('\n', '. ', $matches[0]));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question