Home / CSE / PHP - CS :: Regular Expressions

CSE :: PHP - CS

  1. How many functions does PHP offer for searching and modifying strings using Perl-compatible regular expressions.

  2. A.

     7

    B.

     8

    C.

     9

    D.

     10

    View Answer

    Workspace

    Discuss Discuss in Forum


  3. What will be the output of the following PHP code?

    <?php

    $foods = array("pasta", "steak", "fish", "potatoes");

    $food = preg_grep("/^s/", $foods);

    print_r($food);

    ?>

  4. A.

     Array ( [0] => pasta [1] => steak [2] => fish [3] => potatoes )

    B.

     Array ( [3] => potatoes )

    C.

     Array ( [1] => steak )

    D.

     Array ( [0] => potatoes )

    View Answer

    Workspace

    Discuss Discuss in Forum


  5. Say we have two compare two strings which of the following function/functions can you use?
    1. strcmp()
    2. strcasecmp()
    3. strspn()
    4. strcspn()

  6. A.

     1 and 2

    B.

     3 and 4

    C.

     None of the mentioned

    D.

     All of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum


  7. Which one of the following functions will convert a string to all uppercase?

  8. A.

     strtoupper()

    B.

     uppercase()

    C.

     str_uppercase()

    D.

     struppercase()

    View Answer

    Workspace

    Discuss Discuss in Forum


  9. What will be the output of the following PHP code?

    <?php

    echo str_pad("Salad", 5)." is good.";

    ?>

  10. A.

     SaladSaladSaladSaladSalad is good

    B.

     is good SaladSaladSaladSaladSalad

    C.

     is good Salad

    D.

     Salad is good

    View Answer

    Workspace

    Discuss Discuss in Forum


  11. Which one of the following functions can be used to concatenate array elements to form a single delimited string?

  12. A.

     explode()

    B.

     implode()

    C.

     concat()

    D.

     concatenate()

    View Answer

    Workspace

    Discuss Discuss in Forum


  13. Which one of the following functions finds the last occurrence of a string, returning its numerical position?

  14. A.

     strlastpos()

    B.

     strpos()

    C.

     strlast()

    D.

     strrpos()

    View Answer

    Workspace

    Discuss Discuss in Forum


  15. What will be the output of the following PHP code?

    <?php

    $author = "nachiketh@example.com";

    $author = str_replace("a","@",$author);

    echo "Contact the author of this article at $author.";

    ?>

  16. A.

     Contact the author of this article at nachiketh@ex@mple.com

    B.

     Cont@ct the @uthor of this @rticle @t n@chiketh@ex@mple.com

    C.

     Contact the author of this article at n@chiketh@ex@mple.com

    D.

     Error

    View Answer

    Workspace

    Discuss Discuss in Forum


  17. What will be the output of the following PHP code?

    <?php

    $url = "contact@examveda.com";

    echo ltrim(strstr($url, "@"),"@");

    ?>

  18. A.

     contact@examveda.com

    B.

     contact

    C.

     contact@

    D.

     examveda.com

    View Answer

    Workspace

    Discuss Discuss in Forum


  19. What will be the output of the following PHP code?

    <?php

    $number = array(0,1,two,three,four,5);

    $num = preg_grep("/[0-5]/", $number);

    print_r($num);

    ?>

  20. A.

     Array([0]=>0 [1]=>1 [2]=>two [3]=>three [4]=>four [5]=>5)

    B.

     Array([2]=>two [3]=>three [4]=>four)

    C.

     Array([1]=> 1)

    D.

     Array([0]=>0 [1]=>1 [5]=>5)

    View Answer

    Workspace

    Discuss Discuss in Forum