Jump to content

Url Function


supertrucker
 Share

Recommended Posts

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

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

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...