94512/how-to-extract-urls-from-text-in-php
I have this text:
$string = "this is my friend's website http://example.com I think it is coll";
How can I extract the link into another variable?
I know it should be by using regular expression especially preg_match() but I don't know how?
Hello,
A simple example capturing anything starting with http:// and https:// could be:
preg_match_all('!https?://\S+!', $string, $matches); $all_urls = $matches[0];
Note that this is very basic and could capture invalid URLs.
Hello @kartik, This is not possible in PHP. All ...READ MORE
Hello @kartik, Use the php_sapi_name() function. if (php_sapi_name() == "cli") { ...READ MORE
Hello @kartik, Try using batch file Open notepad type php -S ...READ MORE
Hello, Try this code: if (!function_exists('getallheaders')) { ...READ MORE
Hey @kartik, First you have to go to ...READ MORE
Named route is used to give specific ...READ MORE
Hello, This is simple you just need to ...READ MORE
Hey @kartik, Named routing is another amazing feature of ...READ MORE
Hello @kartik, Use COALESCE: DECLARE @Names VARCHAR(8000) SELECT @Names = ...READ MORE
Hello @kartik, Use array_unique(): Example: $array = array(1, 2, 2, 3); $array ...READ MORE
OR
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.