Display how many characters a field have

Discussion in 'PHP' started by basketmen, Jun 14, 2013.

  1. #1
    i have a field, the field name is name, like
    John
    Robert
    etc

    the variable to call name is $name



    now i need to display how many characters each name have, for example
    John : 4 characters
    Robert : 6 character

    how to get characters numbers by using the name variable $name, what is the query looks like?


    thank you & GBU for all that helping
     
    basketmen, Jun 14, 2013 IP
  2. Devtard

    Devtard Notable Member

    Messages:
    850
    Likes Received:
    133
    Best Answers:
    4
    Trophy Points:
    220
  3. sorindsd

    sorindsd Well-Known Member

    Messages:
    201
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    118
    #3
    select name, length(name) from table --- this will display the name and the length of the field
     
    sorindsd, Jun 15, 2013 IP
  4. Marcel Preda

    Marcel Preda Member

    Messages:
    21
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    43
    #4
    To get strings like
    John : 4 characters
    Robert : 6 characters

    Your code should be:
    print $name." : ".strlen($name)." characters" ;

    BR,
    Marcel
     
    Marcel Preda, Jun 15, 2013 IP