SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jun 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up WEB PAGE CLASSIFICATION

    Sir,

    Thank u for your reply.sir i want to classify the web page by using URL features namely 1.abbreviation.abbreviation in URL,2.abbreviations in slash of URL,3.Number of abbreviations in URL...so that s y i attached my coding i going to classify the web page like sports,education,etc by using URL features.i used explode function for split the above URL abbreviation features and used switch case for string comparison but i ll expect category value like 0,1,2.. for each category.but it doesn't work.

    <?php
    echo "Enter the url";
    echo "<input type=text name='t' value='$t1'>";
    $t1=$_GET['$url'];
    echo "<form method=post action=getdomain($t1)>";

    function getdomain($url)
    {
    $explode = explode(".", $url);
    $tld = $explode[2];
    $tld = explode("/", $tld);
    $x = $explode[1];
    return $x;
    }

    string y[7]={'arts','sports','finance'}
    for(i=0;i<=3;i++)
    {
    b=strcmp($x,$y[i])
    if(b==0)
    {
    c=y[i];
    }
    else
    {
    return "invalid";
    }
    }

    switch ($c)
    {
    case "arts":
    return att1=0;
    break;
    case "sports":
    return att1=1;
    break;
    case "finance":
    return att1=2;
    break;

    }
    ?>

    For output i created form by using label and text box.suppose if i enters the URL name for example WWW.yahoo sports.com means i expecting the sports category value in switch case that is 2.

  2. #2
    SitePoint Addict tom8's Avatar
    Join Date
    Mar 2012
    Location
    New Jersey
    Posts
    310
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I think you need to learn PHP first before attempting to do something like this. I fixed all you syntax as well as logic errors:

    PHP Code:
    <?php
       
    echo "Enter the url";
       
    $t1=$_GET['url'];
       echo 
    "<form method=post action=".getdomain($t1).">";
       echo 
    "<input type=text name='t' value='$t1'>";

       function 
    getdomain($url)
       {
           
    $explode explode("."$url);
           
    $tld $explode[2];
           
    $tld explode("/"$tld);
           
    $x $explode[1];
           return 
    $x;
       }

       
    $y[7]= array("arts","sports","finance");
       for(
    $i=0;$i<=3;$i++)
       {
           
    $b=strcmp($x,$y[$i]);
           if(
    $b==0)
           {
               
    $c=$y[$i];
           }
           else
           {
               return 
    "invalid";
           }
       }

       switch (
    $c)
       {
           case 
    "arts":
               return 
    $att1=0;
               break;
           case 
    "sports":
               return 
    $att1=1;
               break;
           case 
    "finance":
               return 
    $att1=2;
               break;

       }
    ?>
    Note that the above only fixes syntax but not all the logic.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •