Basically, I use gethostbyname()to get the IP address of the specified URL, using parse_url()to determine a specific domain. However, this does not work if http://missing from the URL (if I miss the option)
gethostbyname()
parse_url()
http://
So, how can I check if http://the URL is there, and if not, add it accordingly?
Or, if you have a better alternative, I would like to hear it. Thank.
<?php $url = [some url here]; if(substr($url, 0, 7) != 'http://') { $url = 'http://' . $url; } ?>
, , https , , ftp mailto , . , ":" -, , , , , , , .
<?php $url = [some url here]; if(substr($url, 0, 7) != 'http://') { if(substr($url, 0, 8) != 'https://') { $url = 'http://' . $url; } } ?>
..
A simple solution:
if(!preg_match('/http[s]?:\/\//', $url, $matches)) $url = 'http://'.$url;
if (strpos("http://", $url) === "true"){ action };
Source: https://habr.com/ru/post/1750933/More articles:Associativity in lambda calculus - lambda-calculusGet a list of available types of Drupal - phpHow to format date from timestamp in PHP? - phpImplementing the life cycle of an Android game thread - javaWindows Phone 7 Development, how different is it from version 6.x? - windows-mobileКак я могу обработать возможную утечку памяти из-за исключения в Objective-C? - objective-cwhy using "\" shows an error in jython - jythonCreate a kext to replace switch keys with a key to lock caps or a function key (fn) - osx-snow-leopardHow to replace all values in a hash with a new value? - ruby | fooobar.comorg.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions - springAll Articles