Jump to content

[SOLVED] URLS - Remove and check parts


supanoob

Recommended Posts

I have a system where people can add their favourite sites to my database and people can rate them and comment on them.

 

However i want to check the URL on submittion and if it has http:// at the beginning i want it to remove it. I would also like remove anything after the .com or .co.uk or whatever at the end of the URL so it is taking you directly the to homepage instead of allowing links to images etc.

 

How would i do this?

Link to comment
https://forums.phpfreaks.com/topic/149824-solved-urls-remove-and-check-parts/
Share on other sites

There is a nice function to parse the components of an URL: http://www.php.net/manual/en/function.parse-url.php

 

You need to extract the host component: parse_url($url,PHP_URL_HOST)

 

So that

 

echo parse_url ('http://www.php.net/manual/en/function.parse-url.php',PHP_URL_HOST);

 

will output "www.php.net"

 

There is a nice function to parse the components of an URL: http://www.php.net/manual/en/function.parse-url.php

 

You need to extract the host component: parse_url($url,PHP_URL_HOST)

 

So that

 

echo parse_url ('http://www.php.net/manual/en/function.parse-url.php',PHP_URL_HOST);

 

will output "www.php.net"

 

 

Didnt know about that, thank you :D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.