I have output from a database being stored as a string variable and then used as the meta keywords on my page. So, let's say...
$keywords = "welcome,to,my,website";
Now, I want to remove the two character words (to and my) from this string so that I am left with:
$keywords = "welcome,website";
I tried to explode the $keywords variable, remove the items with a strlen less than 3 and then implode the array, but it's not working. Here is my code.
Code:
$aKeywords = explode(",", $keywords);
$final_keywords = array();
foreach ($aKeywords as $keyword) {
if (strlen($keyword) < 3) {
$keyword = '';
}
$final_keywords[$i] = $keyword;
}
$keywords = implode(",",$final_keywords);
What am I doing wrong? Is there a better approach or am I completely off-base?
Thanks in advance.