Check for http://www |
[eluser]megabyte[/eluser]
I have a form, and one of the fields allows the user to enter their url. whether they enter: http://www.example.com or www.example.com or example.com All I want is to capture it as: example.com Anyone have a function they want to share? I'm sure reg ex. would be a better choice than search and replace using str_replace() and regualr expressions are not my strong point. thanks in advance.
[eluser]gtech[/eluser]
Code: <?php here you go here is an example using preg_match
[eluser]megabyte[/eluser]
thanks, I appreciate the help. tested it out with Code: $url = "http://test.com"; and got this though. Code: http://test.com
[eluser]gtech[/eluser]
the interwebs a wonderfullthing i nicked this: this allows all sorts of weird and wonderful combinations like www.test.co.uk and removes trailing slashes like test.co.uk/asdad/asdasd/sad/dd Code: <?php from here [url="http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_22819065.html"]http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_22819065.html[/url] *note I clicked on the link after I turned scripts off on my browser, using noscript in firefox.. so click on it at your own risk.
[eluser]stevek42[/eluser]
I just made this quickie: Code: <?php Output: $ php test.php test.com test.com test.com test.com sub.test.com
[eluser]megabyte[/eluser]
yes the internet is a wonderous thing, and the members of this forum are even better. thanks so much. and hopefully others get to use this too. |
Welcome Guest, Not a member yet? Register Sign In |