I have full URLs as strings, but I want to remove the http:// at the beginning of the string to display the URL nicely (ex: www.google.com instead of http://www.google.com)
Can someone help?
$removeChar = ["https://", "http://", "/"];
If you want to remove the only http:// from URL. you have use PHP preg_replace() function. <? php // Remove http:// $input = "http://way2tutorial.com"; $input = preg_replace( "#^[^:/.]
To remove http:// or https:// from a url, call the replace() method with the following regular expression - /^https?:\/\// and an empty string as parameters. The replace method will return a new string, where the http:// part is removed. Copied!
$str = 'http://www.google.com'; $str = preg_replace('#^https?://#', '', $str); echo $str; // www.google.com
That will work for both http://
and https://
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With