When manipulating or dealing with URL in PHP programming language, it’s easier to replace all instances of http:// to https:// whenever required, such as when output HTML for web page, when validating the form, or when inserting or updating to the database.
To replace all references to http in PHP to https, use the preg_replace function with the following syntax:
$url = preg_replace("/^http:/i", "https:", $url);