Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,166 questions

40,722 answers

573 users

How to check if a string contains URL in PHP

3 Answers

0 votes
$s = "https://www.collectivesolver.com/ Programming & Software Q&A";

$slink = strpos($s, 'http') !== false || strpos($s, 'www.') !== false;

if (isset($slink))
    echo "yes";
else
    echo "no";
    
    

/*
run:

yes

*/

 





answered Aug 14, 2020 by avibootz
0 votes
$s = "https://www.collectivesolver.com/ Programming & Software Q&A";

$reg_ex = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";

if (preg_match($reg_ex, $s, $url)) {
    print_r($url);
    echo "yes";
}
else
    echo "no";
    
    

/*
run:

Array
(
    [0] => https://www.collectivesolver.com/
    [1] => https
    [2] => /
)
yes

*/

 





answered Aug 14, 2020 by avibootz
0 votes
if (filter_var("https://www.collectivesolver.com/links/bluehost.htm", FILTER_VALIDATE_URL)) {
	echo "yes";
}
else {
	echo "no";
}



/*
run:

yes

*/

 





answered Aug 16, 2020 by avibootz

Related questions

1 answer 66 views
1 answer 75 views
75 views asked Aug 14, 2020 by avibootz
2 answers 246 views
1 answer 139 views
1 answer 80 views
...