Reputation: 7396
I have links put by users and in the database they will be saved
for facebook the urls may be like this
www.facebook.com
http://facebook.com
https://facebook.com
facebook.com
http://www.facebook.com
https://www.facebook.com
But while showing the overall stats to facebook how do I query all at a time Or is there a way to save the urls in database
Upvotes: 3
Views: 95
Reputation: 1966
While counting the number of occurrences of a specific URL, you can use parse_url
~Pseudo Code:
<?php
//Store all url variations from table
//in $all_urls (indexed array)
$fb_count = 0;
for($i=0;$i<count($all_urls);$i++){
$url = parse_url($all_urls[$i]);
if($url[host] == "facebook.com")
$fb_count++;
}
//Now do something/anything-you-want with $fb_count
?>
The code can be more specific if you add the relevant code by which you are fetching the data from table.
Upvotes: 0
Reputation: 4236
You can make a scheme in a database that you store two pieces of data for each URL - the literal url and the standardized one. What you do is you store the URL how you see it (the variations listed above) but using a regular expression, you trim it down to something like facebook.com and store it in the database.
Now you can look up all facebook urls by searching facebook.com but you also know how each entry was entered originally.
Upvotes: 3