PHP find output programs (String Functions) | set 2

Find the output of PHP programs | String Functions | Set 2: Enhance the knowledge of PHP String Functions concepts by solving and finding the output of some PHP programs.
Submitted by Nidhi, on January 24, 2021

Question 1:

<?php
    $A = 10;
    $B = 5;
    
    $C = $A * $B + 20;
    
    echo strrev($C);
?>

Output:

07

Explanation:

In the above program, we created two variables $A and $B initialized with 10 and 5 respectively. Let's evaluate the expression,

$C = $A*$B+20;
$C = 10*5+20;
$C = 50+20;
$C = 70;

After we reverse the value of $C, Then the strrev($C) will print 07 on the webpage.

Question 2:

<?php
    $STR = "Include Help is educational platform";
    $POS = strpos($STR, "is");
    
    echo strrev($POS);
?>

Output:

31

Explanation:

In the above program, we created a string $STR, which is initialized with "Include Help is educational platform" then we used strpos() function to find out the position of the substring "is" in the string $STR. Then function strops() return 13, which is assigned to variable $POS.

Finally, we print the reverse of $POS that will be 31.

Question 3:

<?php
    $STR = "Include Help is educational platform";
    $NEW_STR = str_replace("platform", "website", $STR);
    
    echo $NEW_STR;
?>

Output:

Include Help is an educational website

Explanation:

In the above program, we created a string $STR, which is initialized with "Include Help is educational platform" then we used str_replace() function to replace the specified substring inside the specified string.

Here, we replaced the "platform" substring by "website" in the string $STR. Then str_replace() returns the update string and assigned to $NEW_STR and then finally "Include Help is an educational website" will be printed on the web page.






Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.