Page 1 of 1

how to exclude and find the maiun domain address

Posted: Sun Jul 27, 2008 1:46 am
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

Re: how to exclude and find the maiun domain address

Posted: Sun Jul 27, 2008 3:37 am
by EverLearning
Take a look at parse_url function in PHP Manual.

Re: how to exclude and find the maiun domain address

Posted: Sun Jul 27, 2008 9:11 am
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>";

Re: how to exclude and find the maiun domain address

Posted: Sun Jul 27, 2008 10:16 am
by SidewinderX
Use the LIKE keyword in your query.

Re: how to exclude and find the maiun domain address

Posted: Sun Jul 27, 2008 11:17 am
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

Re: how to exclude and find the maiun domain address

Posted: Sun Jul 27, 2008 11:35 am
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.

Re: how to exclude and find the maiun domain address

Posted: Sun Jul 27, 2008 12:13 pm
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 )

Re: how to exclude and find the maiun domain address

Posted: Sun Jul 27, 2008 12:27 pm
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);