php - replace string occurrences

Viewed 16886

I have a string "First line | second line | third line" How can I replace | with a new line character?

I'm trying to use preg_replace but with no liuck

4 Answers

There is more generic case where e.g. '' serves as replacwment string:

//  Provides: Hll Wrld f PHP
$vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"];
$onlyconsonants = str_replace($vowels, "", "Hello World of PHP");
Related