w3resource
php Programming Exercies

PHP String Exercises: Remove a part of a string from the beginning

PHP String: Exercise-15 with Solution

Write a PHP script to remove a part of a string from the beginning.

Sample string : '[email protected]'

Pictorial Presentation:

PHP String Exercises: Remove a part of a string from the beginning

Sample Solution:

PHP Code:

<?php
$sub_string = '[email protected]';
$str = '[email protected]';
if (substr($str, 0, strlen($sub_string)) == $sub_string) 
{
 $str = substr($str, strlen($sub_string));
}
echo $str."\n";
?>

Sample Output:

example.com

Flowchart :

Flowchart: Remove a part of a string from the beginning

PHP Code Editor:

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

Previous: Write a PHP script to print the next character of a specific character.
Next: Write a PHP script to get a hex dump of a string.

What is the difficulty level of this exercise?



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