Categories
PHP

Refactored – PHP SEO Class v1.0

I am a terrible developer, there’s people out there with amazing skills but I realized long time ago I am not one of them.

Probably way better than average developer out there, you only need to check some WordPress plugins or the core of WordPress to find evil in his greatness xD

Today I’ve found some old code I did back in 2009 that works awfully :S it’s one of the top download classes at php classes and yes it’s just horrible. People uses it and is integrated at Open Classifieds and Open eShop since ever.

Took 5 years for someone to find a weird behaviour and for me to check deeply….

I had a @todo to refactor the class since long time but since it’s working why in earth should I waste time?

I’ve reinvented the wheel in different ways, created a function to count words for example xD use array_count_values(str_word_count(‘some text’,1)) for god sake. Using a loop to cut the word not in the middle and a long etc. Well now all of that fixed…sure could be better, but works good 😉

If you were using the class, migrate from:

$seo = new seo($text, 'UTF-8');
$meta_keywords = $seo->getKeyWords(12);
$meta_description = $seo->getMetaDescription(150);

To:

seo::$charset = 'UTF-8'; //optional by default is always UTF-8
$title = seo::text($title, 70);//before I was not using it for title but I think it's important
$meta_keywords = seo::keywords($meta_description);
$meta_description = seo::text($meta_description);

Download v1.1

Notes

  •  length of title and description from:
    •  http://moz.com/learn/seo/meta-description
    • http://moz.com/learn/seo/title-tag
  • remember keywords are useless!!