Jump to content

str_replace


EchoFool

Recommended Posts

Hey

 

i have a string replace for talk like a pirate day but it doesnt work how i was hopeing :

 

<?php
$text = str_replace(' hey ', 'Yo ho ho, and a bottle of rum!', $text);
?>

 

This currently only works if there is a space either side of "hey" so " hey " is valid "hey" is not valid... i could only do it this way because otherwise words with "hey" in the middle of the word would be replaces such as:

 

So "they" became:

 

"tYo ho ho, and a bottle of rum!"

 

which is annoying - how do i solve that issue?

Link to comment
https://forums.phpfreaks.com/topic/189494-str_replace/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.