supertrucker Posted August 25, 2009 Share Posted August 25, 2009 Perhaps I'm over thinking this, but here is the scenario:Link 1: http://www.example.comLink 2: http://www.example.com/Link 3: http://www.example.com/index.phpLink 4: http://www.example.com/index.php?var=123Link 5: http://www.example.com?var=123All of these links are pointing to the exact same location, but they are all different. I need a method to break down any version to just the http://www.example.com so I can append the address to http://www.example.com/favicon.ico.Things get even more confusing with addresses like:1: http://www.example.com.au/2: http://www.example.com.au/dir/index.php?var=123...where all I need is the http://www.example.com.au part.Any tips on how to achieve this? I'm clunking my head against a wall right now in frustration :)Thanks! Link to comment Share on other sites More sharing options...
Synook Posted August 25, 2009 Share Posted August 25, 2009 Why do you need to get the domain? Why not just use "/favicon.ico"? Link to comment Share on other sites More sharing options...
Ingolme Posted August 25, 2009 Share Posted August 25, 2009 If the domain is from your site, you can access it with the $_SERVER['HOST_NAME'] variable. Link to comment Share on other sites More sharing options...
teng84 Posted August 25, 2009 Share Posted August 25, 2009 try http://www.php.net/manual/en/function.parse-url.php Link to comment Share on other sites More sharing options...
justsomeguy Posted August 25, 2009 Share Posted August 25, 2009 If you want to get information about the current request, just print out the entire $_SERVER array and see what's available. Link to comment Share on other sites More sharing options...
supertrucker Posted August 26, 2009 Author Share Posted August 26, 2009 Thanks guys, Teng84 hit it on the nail, never ran across those functions before, very handy!I run a very large mobile internet directory, and some of the links are in the formats listed above. That's why I needed to be able to break each link down, so I can display their pretty icons. I have it working now, but I'm not entirely happy with my quick fix. I need to write a preg_match statement. Anyone decent at writing reg exp's? I tried and butchered it. Link to comment Share on other sites More sharing options...
justsomeguy Posted August 26, 2009 Share Posted August 26, 2009 What do you need regular expressions for? The parse_url function will give you the host, that's the only thing you need to get the favicon. Link to comment Share on other sites More sharing options...
supertrucker Posted August 27, 2009 Author Share Posted August 27, 2009 In theory you are correct, but there, unfortunately, are scenarios where developers don't follow the typical rules. Here's a standard favicon declaration: <link rel="shortcut icon" href="favicon.ico" /> Sometimes, I've seen people do this: <link rel="shortcut icon" href="/images/favicon.ico" /> Or even this: <link rel="shortcut icon" href="myicon.ico" /> So, best practice would probably, I'm assuming, be to do a preg_match for the "myicon.ico". My problem is just that I seem to be struggling with reg exps.Tips? Link to comment Share on other sites More sharing options...
justsomeguy Posted August 27, 2009 Share Posted August 27, 2009 You might need 2 regexps, or a pattern with an OR. You need to look for either a link tag that has a rel with "shortcut icon" followed by an href, or a link tag with an href followed by a rel with "shortcut icon". There are a bunch of regexp examples around, and the PHP manual for preg includes another reference. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.