Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • String in php

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 117
    Comment on it

    A string is sequence of character.
    Every thing that is declared in a string will considered as a character.

    Like abcd1234 is a string.

    And when you add the string like 2+2 will give 22 not 4.

    PHP string function

    strlen()- It is used to find the length of the string. It can also count the number of spaces and character.

    ex-

    <?php
    echo strlen("Hello people"); // outputs 12
    ?>

    str_word_count()- It is used to count the number of word that are there in the string. It count the word after the space. So in short the number of spaces with addition of 1 can give your number of word.

    ex-

    <?php
    echo str_word_count("Hello people"); // outputs 2
    ?>

    strrev()- It is use to get the reverse of a string.

    ex-

    <?php
    echo strrev("Hello people"); // outputs elpoep olleH
    ?>

    strpos()- It is use to search a specific word or string in a given string. It returned 6 because the first letter of the search string is found on the 6 place.

    <?php
    echo strpos("Hello people", "people"); // outputs 6
    ?>

    str_replace()- It is use to replace the string with another string.

    ex-

    <?php
    echo str_replace("people", "girls", "Hello people"); // outputs Hello girls
    ?>

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: