Home / CSE / PHP - CS :: Regular Expressions

CSE :: PHP - CS

  1. What will be the output if we replace the line $num = preg_grep(“/[0-5]/”, $number); with $num = preg_grep(“/[0-5]/”, $number, PREG_GREP_INVERT);?

  2. 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 [5]=>5)


  3. Which one of the following functions is used to search a string?

  4. A.

     preg_match

    B.

     preg_search

    C.

     preg_find

    D.

     preg_found


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

    <?php

    $name = "What is your name?"

    if (preg_match("/name/"),$name)

    echo "My name is Will Pitt ";

    else

    echo "My name is not Will Pitt ";

    if (preg_match("/are/"))

    echo "I am great"

    else

    echo "I am not great";

    ?>

  6. A.

     My name is Will Pitt I am great

    B.

     My name is not Will Pitt I am great

    C.

     My name is Will Pitt I am not great

    D.

     My name is not Will Pitt I am not great


  7. Which one of the following preg PHP function is used to do a find and replace on a string or an array?

  8. A.

     preg_replace()

    B.

     preg_find()

    C.

     preg_find_replace()

    D.

     preg_findre()


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

    <?php

    $str = "Hello! My name is Cameron Fox. Coffee?"

    $find = array('/is/','/coffee/');

    $replace = array('/was/','/tea/');

    echo preg_replace ($find, $replace, $str);

    ?>

  10. A.

     Hello! My name was Cameron Fox. tea?

    B.

     Hello! My name is Cameron Fox. tea?

    C.

     Hello! My name is Cameron Fox. Coffee?

    D.

     Hello! My name was Cameron Fox. Coffee?


  11. Which one of the following preg PHP functions is used to take a string, and put it in an array?

  12. A.

     preg_destroy()

    B.

     preg_split()

    C.

     preg_unchain()

    D.

     preg_divide()


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

    <?php

    $line = "You like dogs. I hate dogs. We should marry."

    $sen = preg_split('/./', $line);

    print_r($sen);

    ?>

  14. A.

     You like dogs. I hate dogs. We should marry.

    B.

     Array([0]=>You like dogs. I hate dogs. We should marry.)

    C.

     Array([0]=>You like dogs. [1]=>I hate dogs. [2]=>We should marry.)

    D.

     Error


  15. Which one of the following is not a preg PHP function?

  16. A.

     preg_match

    B.

     preg_match_all

    C.

     preg_matchall

    D.

     preg_split


  17. Parameter flags was added in which version of PHP?

  18. A.

     PHP 4.0

    B.

     PHP 4.1

    C.

     PHP 4.2

    D.

     PHP 4.3