D
D
Diversia2018-02-27 11:59:37
PHP
Diversia, 2018-02-27 11:59:37

How to extract only a link from a string in PHP?

Please tell me how to extract only a link from a string:

текст текст https://toster.ru/question/new/?get любой текст

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Stalker_RED, 2018-02-27
@Stalker_RED

Regular, for example: https:\/\/[^\s]*
https://regex101.com/r/riu31t/1
see RFC 3986 (Section 2: Characters)

https?:\/\/[!#$&-;=?-[\]_a-z~]*

M
metallix, 2018-02-27
@metallix

Why can't you google? there's a bunch of answers
Extract URL's from a string using PHP

D
Dmitry, 2018-02-27
@slo_nik

Good afternoon.
PHP has a global array $_SERVER .
And in this array there is an index "QUERY_STRING", which contains the data passed in the address after the "?"
There is also "HTTP_HOST", which contains the domain name.
There is a ton of stuff, follow the link and see what you can get out of this array.
Just do it on the right page print_r($_SERVER)and see what it gives you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question