w3resource
php Programming Exercies

PHP String Exercises: Replace multiple characters from a string

PHP String: Exercise-23 with Solution

Write a PHP script to replace multiple characters from the following string.

Sample String : '\"\1+2/3*2:2-3/4*3'

Sample Solution:

PHP Code:

<?php
$my_str = '\"\1+2/3*2:2-3/4*3';
echo str_replace(str_split('\\/:*?"<>|+-'), ' ', $my_str)."\n";
?>

Sample Output:

1 2 3 2 2 3 4 3

Flowchart :

Flowchart: Replace multiple characters from a string

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 characters after the last '/' in an url.
Next: Write a PHP script to select first 5 words from the specified string.

What is the difficulty level of this exercise?



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