View Single Post
  #1 (permalink)  
Old 03-15-2008, 10:40 PM
krnl krnl is offline
WebProWorld Member
 

Join Date: Jan 2006
Location: USA
Posts: 41
krnl RepRank 0
Default Strings and arrays in PHP

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.
__________________
Rick - Linux Tutorials for Beginners
allin-enterprises.com | all-in-general.com | MagliteSales.com | DiscountFishTackle.com
Reply With Quote