need help in php script

Discussion in 'PHP' started by mahiraj, Oct 9, 2007.

  1. #1
    Hi all I am new in php please helpe to write the script whic take the following string

    YELLOW MANGOES RED APPLES RED IS MY FAVORITE COLOR MY SHIR IS ALSO RED BUT I DO NOT LIKE YELLOW AND GREEN A COW EATS GREEN GRASS GREEN VISITABLE IS USEFUL FOR HEALTH

    and through echo statement it should display the word which comes mostly in this script.

    please help me to do this

    I will very grateful to you.
     
    mahiraj, Oct 9, 2007 IP
  2. foreststone

    foreststone Peon

    Messages:
    1,355
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    can not understand , your script will do what for you
     
    foreststone, Oct 9, 2007 IP
  3. mahiraj

    mahiraj Guest

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I Want to write the script for acceptance for that script and find the word for which comes mostly in it for e.g "RED". then display to it.........
     
    mahiraj, Oct 9, 2007 IP
  4. live-cms_com

    live-cms_com Notable Member

    Messages:
    3,128
    Likes Received:
    112
    Best Answers:
    0
    Trophy Points:
    205
    Digital Goods:
    1
    #4
    Explode the string by " " then put each word into an array like $array[word][0], if the word is already in the array increment the number after it.
     
    live-cms_com, Oct 9, 2007 IP
  5. webmaterials.com

    webmaterials.com Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hi

    How about this.

    And by the way "RED" is not the most common word, "RED", "IS", "GREEN" are all equally common :)

    <?php

    $string="YELLOW MANGOES RED APPLES RED IS MY FAVORITE COLOR MY SHIR IS ALSO RED BUT I DO NOT LIKE YELLOW AND GREEN A COW EATS GREEN GRASS GREEN VISITABLE IS USEFUL FOR HEALTH";

    $words=explode(" ", $string);
    $frequency=array_count_values($words);
    $most=max($frequency);
    print_r(array_keys($frequency, $most));

    ?>


    Gives

    Array ( [0] => RED [1] => IS [2] => GREEN )

    Kind regards

    Henry
     
    webmaterials.com, Oct 10, 2007 IP
  6. mahiraj

    mahiraj Guest

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks a lot man .........
    Its working .......... GRATE........
     
    mahiraj, Oct 10, 2007 IP