I don't understand the part of a method help...

Discussion in 'PHP' started by co.ador, Jul 18, 2009.

  1. #1
    The code below is a method which is part of a class call rating. The bit of code below is just the first part of the OutputRating class I don't understand some of the functions it uses in it. such as addslashes and strlen. I have heard that the magic quotes functions is not necessary any more after php 5. But I think the rest of the code will need an explanation I will greatly appreciate your help.

     public static function OutputRating($varItem)
          {
            // Verify $varItem was provided
            if ($varItem != null && strlen(trim($varItem)) != 0)
            {
              // Check if Magic QUotes is ON
              if (!get_magic_quotes_gpc())
              {
                $varItem = addslashes($varItem);
              }
    PHP:
     
    co.ador, Jul 18, 2009 IP
  2. zeronese

    zeronese Peon

    Messages:
    83
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    strlen : returns the length of a string.
    addslashes: puts slashes infront of strange characters such as single qoutes. this makes strings safer to insert in mysql.
    trim: just takes away the spaces if they are at the start or end of the string.

    by the way, you can always go to
    php.net/THE_NAME_OF_THE_FUNCTION_GOES_HERE
    ex: php.net/strlen
    to check the details of any php function
     
    zeronese, Jul 18, 2009 IP
  3. co.ador

    co.ador Peon

    Messages:
    120
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you bro. In this script instead of outing null it could a 0 as well rigth?
     
    co.ador, Jul 18, 2009 IP
  4. vpdesigns

    vpdesigns Peon

    Messages:
    353
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    strlen(trim($varItem)) != 0 i believe they are using 0 at this point because they are checking the length. But they could have used null as well.
     
    vpdesigns, Jul 18, 2009 IP
  5. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #5
    so doesn't addslashes just do what mysql_escape_string does? which is preferable ?
     
    wd_2k6, Jul 19, 2009 IP
  6. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #6
    Straight from the manual page :
     
    shallowink, Jul 19, 2009 IP