Currently I am using parse_url, however the host item of the array also includes the 'WWW' part which I do not want. How would I go about removing this?
$parse = parse_url($url);
print_r($parse);
$url = $parse['host'] . $parse['path'];
echo $url;
Remove http://, www., and slashes from the URL First is trim() function, use for remove all slash from the URL. Second is preg_match() function, check http:// or https:// existed in URL. If yes then no need to http:// prepend otherwise you have to http:// prepend to URL. Third is parse_url() function, to parse the URL.
$removeChar = ["https://", "http://", "/"];
Solution. Use strip_tags( ) to remove HTML and PHP tags from a string: $html = '<a href="http://www.oreilly.com">I <b>love computer books. </b></a>'; print strip_tags($html); I love computer books.
$url = preg_replace('#^www\.(.+\.)#i', '$1', $parse['host']) . $parse['path'];
This won't remove the www
in www.com
, but www.www.com
results in www.com
.
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