SEO Functions for PHP
It’s known for all of us that SEO it’s really important at any web.
Because of that at many projects I used few functions to make the SEO work properly.
Here you have 2 important one’s:
Description: We erase all the possibles HTML characters, returns and we keep just 220 chars.
function getMetaDescription($text){//returns a text with a proper meta description $text = strip_tags($text);//erase possible html tags $text = str_replace (array('\r\n', '\n', '+'), ' ', $text);//replace possible returns $text = substr($text, 0, 220);//we need only 220 characters return $text."..."; }
Meta Keyword:Erases special chars such as HTML, returns, commas…deletes repeated values and keywords smaller than 3.
function getKeyWords($text){//from the given text $text = strip_tags($text);//erase possible html tags $text = str_replace (array('\r\n', '\n', '+'), ' ', $text);//replace possible returns $text = str_replace (array('-','(',')','+','-'), '', $text);//replace not valid character $text = str_replace (' ', ',', $text);//replace for comas //erase minor than 3, and repeated ones $arrText=explode(",",$text); $arrText=array_unique($arrText);//erase the repeated values $text=array(); foreach ($arrText as &$value) { if (strlen($value)>=3) array_push($text,$value); } unset($value); $text=implode(",",$text); return $text; }
In the keywords function we can improve how many keywords to return (normally max of 25), also when we take from that 25 ones, we should count how many repetitions and erase the less repeated ones…I will work on this and paste it here when I have it ;)
Related Posts- neoMobile - HTML Template for mobile browser
- WP-PageScroll, Plugin for WordPress
- phpMyDB - Data base class for MySql
- phpSEO - Class for better SEO in PHP
- Count Words Repetitions in PHP
- Depth Chart Preview
- Working With A Partnership Program
- Attorney: Abortion Doctor George Tiller Killed at Church
- Main Hints To Maximize Web Traffic .
- Bing Maloney Golf Course, Sacramento, CA
Help sharing and Flatter me ;)

[...] I wrote some functions for better SEO in PHP, but I realized that the Keywords are not so [...]
my site uses utf-8 and language is Catalan (Romance language contains words with accents such as: és, demà …., and the apostrophe is also used as: d’una, l’utilitat….) the problem is that the keywords show wrong the accented characters.
How could I fix it?
Hola! soc de barcelona, entenc el problema ;)
But I will answer to you in English if you don’t mind since like this everybody can understand it.
Instead of using this functions I do recommend to you this last php class: http://neo22s.com/phpseo/
For accents I should be no problem, but for the apostrophe, I do recommend to you to replace it for an empty space. Then it would disappear and consider it as a single word!
Saluts!
hola chema, també sóc català
chema,
pel que fa als apòstrofs he provat d’afegir això:
$text = str_replace (“‘”, ‘ ‘, $text);//replace for apostrofs
però els continua mostrant igualment:
d\ avui, d\ agricultura,
com pases els parametres? magic quotes? crec que si…aquest es el problema ;)
no em refereixo com crides la funció? com pases el parametres?
de moment estic utilitzant les pàgines que has deixat a phpclasses.org, la d’exemple i la de la classe
ho pots veure a: http://www.viladetora.net/includes/example.php
pel que fa als textes per comprovar els resultats, els agafo de:
http://www.viladetora.net/0-noticia-667-els_experts_destaquen_que_els_transgenics_no_aconseguiran_acabar_amb_la_fam_al_mon.html
pots probar aixo:
if ($_POST) $text=stripslashes($_POST["text"]);
;) crec que funcionará!
saluts!
chema, amb la modificació ja funciona, els apostrofs han desaparegut, però en els keywords encara em surten: d agricultura o d avui.
Si hi ha un espai, no haurien de surtir, oi?.
Gràcies per la teva paciència :)
no no hi haurin de sortir, primer has de esborrar (cambi per espai en blanc) l’apostrof y despres netejar els blancs.
Tranquil! ara m’em vaig, si vols continuar aixo sius plau usa el forum ;) es mes facil per mi!
records!
I have been searching for sites related to this. Glad I found you. Thanks
enjoy, and welcome!