Q:

PHP find output programs (String Functions) | set 1

belongs to collection: PHP Find Output Programs

0

Find the output of PHP programs | String Functions | Set 1: Enhance the knowledge of PHP String Functions concepts by solving and finding the output of some PHP programs.

Question 1:

<?php
    $str1 = "ABC";
    $str2 = "LMNO";
    
    $len = $str1 . strlen() + $str2 . strlen();
    echo $len;
?>

Question 2:

<?php
    $str1 = "ABC";
    $str2 = "1234";
    
    $num = 5678;
    
    $len = strlen($str1) + strlen($str2) + strlen($num);
    
    echo $len;
?>

Question 3:

<?php
    $str1 = "Include";
    $str2 = "Help";
    $str3 = "Com";
    
    $str = $str1 . $str2 . $str3;
    echo str_word_count($str);
?>

Question 4:

<?php
    $str1 = "Include";
    $str2 = "-Help";
    $str3 = ".Com";
    
    $str = $str1 . $str2 . $str3;
    echo str_word_count($str);
?>

Question 5:

<?php
    $str1 = "Include";
    $str2 = "-Help";
    $str3 = ".Com";
    
    $str = $str1 . $str2 . $str3;
    echo str_rev($str);
?>

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer 1:

Output:

0

Explanation:

The above program will print 0 on the console screen. In the above program, we defined two-variable $str1 and $str2. Here, we used strlen() function. But the strlen() function is not used correctly.

The proper syntax for strlen() function is given below:

$len = strlen($str1) + strlen($str2);

The $str1.strlen() and $str2.strlen() will return nothing then the value of $len will be 0, that will be printed on the webpage.

Answer 2:

Output:

11

Explanation:

In the above program, we created three variables $str1, $str2, and $num that are initialized with "ABC", "1234", and 5678 respectively.

Here, we used strlen(), which is used to calculate the length of specified string as we as number. Let's evaluate the expression.

$len = strlen($str1) + strlen($str2)+ strlen($num);
$len = 3 + 4 + 4;
$len = 11;

Then the final value of $len will print on the web page.

Answer 3:

Output:

1

Explanation:

The above program will print 1 on the webpage. In the above program, we created three variables $str1, $str2, and $num that are initialized with "Include", "Help", and "Com" respectively.

$str =$str1.$str2.$str3;

In the above statement we concatenate $str1, $str2, and $str3, then the value of $str will be "IncludeHelpCom".

The "IncludeHelpCom" is a signal word then the str_word_count() will return 1, that will be printed on the webpage.

Answer 4:

Output:

2

Explanation:

In the above program, we created three variables $str1, $str2, and $num that are initialized with "Include", "-Help", and ".Com" respectively.

In the above statement we concatenate $str1, $str2, and $str3, then the value of $str will be "Include-Help.Com".

The string "Include-Help.Com" contains two words "Include-Help" and ".Com". Because words are also treat separated based on the dot '.', then str_word_count() will return 2, which will be printed on the web page.

Answer5:

Output:

PHP Fatal error:  Uncaught Error: Call to undefined function str_rev() 
in /home/main.php:7
Stack trace:
#0 {main}
  thrown in /home/main.php on line 7

Explanation:

The above program will generate the compile-time error because str_rev() is not a built-in function in PHP. To reverse a string in PHP, we need to use strrev() function instead of str_rev().

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP Find Output Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
PHP find output programs (String Functions) | set ... >>
<< PHP find output programs (User-defined functions) ...