Results 1 to 4 of 4

Thread: PHP - Count number of words

  1. #1
    Join Date
    Nov 2009
    Posts
    518

    PHP - Count number of words

    Hi
    I have recently started coding in PHP. It is really good and I liked it very much. I have done some small programs in PHP. From few day I am just wondering that is it possible to count how many times a word i repeated on an external site. That is want to code a program that will count a word repeated on an external site and it will display an output. is it possible? I am not so sure that my question is correct or this can be done or not. If it is possible to do, then can you guys post me some codes so that I can study them. Thanks in advance.

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    Re: PHP - Count number of words

    Hi
    I think you can try something like this
    Code:
    $cnt = 0;
    while($conts = file_get_conts("URL")){
    
          $cnt = substr_cnt($conts,"$your_string");
    
    }
    I have not tested it, but still, i think this will work. Have a try at it. If any more queries do post back.

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    Re: PHP - Count number of words

    Hi
    May be this program is what you are looking for. Just go through it
    Code:
    $cnt = 0;
    $t=0;
    $conts = file_get_conts("URL");
    $leng=strlen($conts);
    for ($i=0;$i<$leng;$i++);
    if($conts[$i]==" " && $conts[$i+1]!=" ")
    {$arrstr[$t]=$conts[$i+1];
    $t++;
    }
    $len=cnt($arrstr);
    $ct=0;
    for ($i=0;$i<$len;$i++);
    {
    for ($j=0;$j<$leng;$j++)
    {if($arrstr[$i]==$conts[$j])
    $ct++;
    }
    $ntime[$q]=$ct;
    $ct=0;
    }
    $j=0;
    for ($i=0;$i<$len;$i++);
    {
    echo "Number of time the words" . $arrstr[$i]."repeats is".$ntime[$j];
    $j++;
    }
    Do not forget to post the feedback.

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: PHP - Count number of words

    Hi
    The above should work fine. But I am posting you a part of the code. Just read it carefully and you can create a program that you were talking about.
    Code:
    $url = 'http://www.google.com/';
    $conts = strtolower(strip_tags(file_get_conts($url)));
    $conts = preg_replace('%[^\w\s\r\n]%', ' ', $conts);
    $wds = preg_split('%[\s\r\n]+%', $conts);
    $wdcnt = array_count_values($wds);
    asort($wdcnt);
    echo '<pre>'.print_r($wdcnt, true).'</pre>';
    If you have any more queries then feel free to post back again. Enjoy programming.

Similar Threads

  1. Replies: 3
    Last Post: 27-11-2010, 12:59 AM
  2. Is anybody how to count number of words in MS Words?
    By Sonam Goenka in forum Windows Software
    Replies: 5
    Last Post: 21-01-2010, 02:49 PM
  3. How to count number of words automatically?
    By Basaam in forum Windows Software
    Replies: 4
    Last Post: 25-04-2009, 10:00 PM
  4. How To Count The Number Of Characters?
    By Harsh01 in forum Software Development
    Replies: 2
    Last Post: 13-02-2009, 12:25 PM

Tags for this Thread

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
  •  
Page generated in 1,713,518,403.73289 seconds with 17 queries