I'm trying to write a script that will take a text string and will allow me replace random words. For example:
$str = "The quick brown fox jumps over the lazy dog";
I will out put as and replace couple words like this:
The quick ______ fox jumps over the ____ dog
I can probably do this by first splitting the string into array
$arr = str_word_count($str, 1);
And then replace $arr[2]
and $arr[7]
.
The issue that I think I'll have if there are non-words in the string, like punctuation:
$str = "The quick brown fox, named Jack, jumps over the lazy dog; and Bingo was his...";
How do I go about resolving this? Ideas?
My Answer:
"Hello, how are you doing today? I hope you are having a great day."
I want to replace random words in this string with new words. Can you help me with the code for this?
Rate this post
3 of 5 based on 1418 votesComments