how to exclude and find the maiun domain address

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aneeshtan
Forum Newbie
Posts: 7
Joined: Sun Jul 27, 2008 1:42 am

how to exclude and find the maiun domain address

Post by aneeshtan »

Hi ,

my question is how to find the main domain and exclude other characters , for instance :

http://www.tarjome.org/something/blah_blah.php

and then convert to :

http://www.tarjome.org

i tried preg_replace but nothing useful came out

any suggestion would be appreciated

thanks
User avatar
EverLearning
Forum Contributor
Posts: 282
Joined: Sat Feb 23, 2008 3:49 am
Location: Niš, Serbia

Re: how to exclude and find the maiun domain address

Post by EverLearning »

Take a look at parse_url function in PHP Manual.
aneeshtan
Forum Newbie
Posts: 7
Joined: Sun Jul 27, 2008 1:42 am

Re: how to exclude and find the maiun domain address

Post by aneeshtan »

Thanks for ur nice solution

but i considered how to count similar pages :

I want to count referrer from websites but it's not important where of that domain they came to my site

e.g. : http://www.yours.com
http://www.yours.com/blah_blah

then the script count this 2 http://www.yours.com not 1 http://www.yours.com and 1 http://www.yours.com/blah_blah

this is my script

Code: Select all

 
$query = "SELECT url ,COUNT(rid) FROM ".$prefix."_referer GROUP BY  url ORDER BY COUNT(rid) DESC LIMIT 0,".$ref;
$result2 = mysql_query($query) or die(mysql_error());
while($row2 = mysql_fetch_array($result2)){
    $numrid =intval($row2['COUNT(rid)']);
    $url =check_html($row2['url'], "nohtml");
    $Domain = parse_url("$url");
    $repurls = $Domain["host"];
    $repurlsshort = str_replace("_", " ", $repurls);
    if(strlen($repurlsshort) > 18) {
      $repurlsshort = substr($repurls,0,20);
      $repurlsshort .= "..";
    }
    echo  $a.":&nbsp;<a href=\"http://".$repurls."\" target=\"new\">".$repurlsshort."</a><font color='red'><b>$numrid</b></font><br>";
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Re: how to exclude and find the maiun domain address

Post by SidewinderX »

Use the LIKE keyword in your query.
aneeshtan
Forum Newbie
Posts: 7
Joined: Sun Jul 27, 2008 1:42 am

Re: how to exclude and find the maiun domain address

Post by aneeshtan »

similar data can be fetched but can not count them ?! 8O

look at my above codes and example .. my main concern is how to count similar data

thanks
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Re: how to exclude and find the maiun domain address

Post by SidewinderX »

Well, perhaps rather than using the query to count, fetch the similar data as I suggested, then use mysql_num_rows to count the result set.
aneeshtan
Forum Newbie
Posts: 7
Joined: Sun Jul 27, 2008 1:42 am

Re: how to exclude and find the maiun domain address

Post by aneeshtan »

thanks.

for the last request can you show me in code .. ( please edit my previous codes that it can able to count similar data )
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Re: how to exclude and find the maiun domain address

Post by SidewinderX »

Code: Select all

$domain = "yours.com";
$query = "SELECT `url` FROM ".$prefix."_referer WHERE `url` LIKE %".$domain."%";
$result = mysql_query($query);
$amount = mysql_num_rows($result);
Post Reply