php - select 1 random keyword per line in txt

Solution:
To select a random keyword from that file:
<?php
//$keywords = file('keyword.txt'); OR
$keywords = explode("\n", file_get_contents('keyword.txt'));
echo $keywords[ array_rand($keywords) ];
?>
Answer
Solution:
I'm not sure I understand the question correctly, but if you want to replace your current keyword selection with a random keyword per line, you need to change:
$kwd=$kw[$i];
with something like:
$kwds = explode(" ", $kw[$i]); // although I would use foreach to loop through the lines array...
$kwd = reset(shuffle($kwds)); // shuffle the keywords in that line and pick the first one
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: warning: undefined array key
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.