U
U
uaf0x2016-02-25 18:08:54
PHP
uaf0x, 2016-02-25 18:08:54

How to replace one random word in text?

You need to find one random word in the text, preferably in the middle of the text and make it a link, share the regular expression plz :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Arkh, 2016-02-25
@AlekseyArh

$text = 'мля блая сиука ыыв ыыв фвы  выф';
$arr = explode(' ', $text);
$word = $arr[rand(0, count($arr)-1)];
$text = str_replace($word,'<a href="/">' . $word . '</a>' ,$text);
print_r($text);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question