itsureboy Posted May 22, 2010 Share Posted May 22, 2010 I need some simple code that would take a URL and convert it to its utmost proper form which would be for example, http://www.site.com So if a user submits the URL short without the http://, or www. the code would add it accordingly. Any help. Thanks ahead. Link to comment https://forums.phpfreaks.com/topic/202614-need-a-simple-url-converter/ Share on other sites More sharing options...
Daniel0 Posted May 22, 2010 Share Posted May 22, 2010 Well, you could do if (strncmp($url, 'http://', 7) != 0) { $url = 'http://' . $url; } You're wrong about the www stuff. The domain name www.example.com doesn't need to point to the same place as example.com. Link to comment https://forums.phpfreaks.com/topic/202614-need-a-simple-url-converter/#findComment-1062077 Share on other sites More sharing options...
paddyhaig Posted May 23, 2010 Share Posted May 23, 2010 It's possible you could use a redirect like so, of course putting what you would like in the url. <?php ob_start(); header("Location: http://en.wikipedia.org"); ob_flush(); ?> Link to comment https://forums.phpfreaks.com/topic/202614-need-a-simple-url-converter/#findComment-1062080 Share on other sites More sharing options...
Daniel0 Posted May 23, 2010 Share Posted May 23, 2010 How would redirecting the user take care of normalizing the string? Link to comment https://forums.phpfreaks.com/topic/202614-need-a-simple-url-converter/#findComment-1062082 Share on other sites More sharing options...
Rustywolf Posted May 23, 2010 Share Posted May 23, 2010 or just, if you want. $url = str_replace('http://', $url); $url = 'http://' . $url; But daniel's way sounds better. Link to comment https://forums.phpfreaks.com/topic/202614-need-a-simple-url-converter/#findComment-1062144 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.