w3resource
php Programming Exercies

PHP String Exercises: Print the next character of a specific character

PHP String: Exercise-14 with Solution

Write a PHP script to print the next character of a specific character.

Pictorial Presentation:

PHP String Exercises: Print the next character of a specific character

Sample character : 'a'
Sample character : 'z'

Sample Solution:

PHP Code:

<?php
$cha = 'a';
$next_cha = ++$cha; 
//The following if condition prevent you to go beyond 'z' or 'Z' and will reset to 'a' or 'A'.
if (strlen($next_cha) > 1) 
{
 $next_cha = $next_cha[0];
 }
echo $next_cha."\n";
?>

Sample Output:

b

Flowchart :

Flowchart: Print the next character of a specific character

PHP Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a PHP script to get the filename component of the specified path.
Next: Write a PHP script to remove a part of a string from the beginning.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming