basic php help nedded :)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • roly
    Confirmed User
    • Aug 2002
    • 1844

    #1

    basic php help nedded :)

    hi

    I'm a newbie with php and need a little help if anyone could provide it. i'm trying to load a list of words from a file and lower the case of the words and remove duplicates. It all works except the changing the words to lower case, but it doesn't through up any errors. This is only part of my script but it's that, that doesn't work. like i say i'm a php newbie so it might be something stupid. Any help appreciated

    if (is_uploaded_file($userfile)) {
    $linesraw = file ("$userfile");
    $phraselower = array_change_key_case($linesraw, CASE_LOWER);
    $lines = array_unique($phraselower);

    thanks in advance
  • AcidMax
    Confirmed User
    • May 2002
    • 1827

    #2
    try print_r($phraselower) and see if it is printing the right data out first.
    Latest MMA news. http://www.mmawrapup.com

    Comment

    • roly
      Confirmed User
      • Aug 2002
      • 1844

      #3
      ok thanks

      Comment

      • duroflex
        Confirmed User
        • Dec 2002
        • 199

        #4
        Have you checked whether your ISP is using an older version of PHP in which the "array_change_key_case" function is not supported?
        ZiggydiZig!

        Comment

        • roly
          Confirmed User
          • Aug 2002
          • 1844

          #5
          no print_r($phraselower) gives all as upper and lower case.

          duroflex, yes i checked and array_change_key_case is for >= 4.2 and i'm running 4.2.2

          Comment

          • Brujah
            Beer Money Baron
            • Jan 2001
            • 22157

            #6
            Without checking, the Key isn't what you're trying to make lowercase probably. Looks like you're trying to get the Values lowercase.

            Comment

            • roly
              Confirmed User
              • Aug 2002
              • 1844

              #7
              Originally posted by Brujah
              Without checking, the Key isn't what you're trying to make lowercase probably. Looks like you're trying to get the Values lowercase.
              thanks brujah, yes i think that may be it. it's the value i'm trying to change not the key.

              Comment

              • Brujah
                Beer Money Baron
                • Jan 2001
                • 22157

                #8
                Originally posted by roly
                hi

                I'm a newbie with php and need a little help if anyone could provide it. i'm trying to load a list of words from a file and lower the case of the words and remove duplicates. It all works except the changing the words to lower case, but it doesn't through up any errors. This is only part of my script but it's that, that doesn't work. like i say i'm a php newbie so it might be something stupid. Any help appreciated

                if (is_uploaded_file($userfile)) {
                $linesraw = file ("$userfile");
                $phraselower = array_change_key_case($linesraw, CASE_LOWER);
                $lines = array_unique($phraselower);

                thanks in advance
                try:

                $linesraw = file ("$userfile");
                while(list(,$phrase)=each($linesraw)) {
                $lines[] = strtolower(trim($phrase));
                }

                Comment

                • roly
                  Confirmed User
                  • Aug 2002
                  • 1844

                  #9
                  Originally posted by Brujah


                  try:

                  $linesraw = file ("$userfile");
                  while(list(,$phrase)=each($linesraw)) {
                  $lines[] = strtolower(trim($phrase));
                  }
                  i think the file command above puts data into an array and the strtolower is for strings so that wont work i don't think, but i get the idea.

                  but you were correct i was trying to change the case of the number and not the word. i have sorted it by using array_flip and all works good now. thanks to all for the help.

                  btw one last stupid question, if an array was like this:

                  $input_array = array("FirSt" => 1, "SecOnd" => 2);

                  is "FirSt" classed as the key or the value of the array

                  Comment

                  • Brujah
                    Beer Money Baron
                    • Jan 2001
                    • 22157

                    #10
                    Originally posted by roly

                    i think the file command above puts data into an array and the strtolower is for strings so that wont work i don't think, but i get the idea.
                    Yes, file() function did put the contents of the file into an array.

                    But the list(,$phrase)=each($linesraw) line is reading the array and putting the value into $phrase.

                    The line within the while statement is trimming the $phrase for you (it probably contains linefeed characters at the end of each value) and putting the lowercase value into $lines array for you.

                    You can run array_unique() on that, and it should work fine.


                    btw one last stupid question, if an array was like this:

                    $input_array = array("FirSt" => 1, "SecOnd" => 2);

                    is "FirSt" classed as the key or the value of the array
                    Yes, that's the key.

                    Comment

                    • roly
                      Confirmed User
                      • Aug 2002
                      • 1844

                      #11
                      great thanks for all your help

                      Comment

                      Working...