Jump to content
php.lv forumi

php html seo linku apmaiņa


Wuu

Recommended Posts

Ši funkcija pārveido nestandarta link tekstu par lietojamu ,bez garumzīmēm.

piem

 

Pārdošanā nonāk EA sporta spēles -> pardosana-nonak-ea-sporta-speles

 

function clean_url($text){
$text=strtolower($text);
$code_entities_match = array('ā','ē','ū','ī','š','ģ','ķ','ļ','ž','ņ',' ','--','"','!','@','#','$','%','^','&','*','(',')','_','+','{','}','|',':','"','<','>','?','[',']','\\',';',"'",',','.','/','*','+','~','`','=');
$code_entities_replace = array('a','e','u','i','s','g','k','l','z','n','-','-','','','','','','','','','','','','','','','','','','','','','','','','');
$text = str_replace($code_entities_match, $code_entities_replace, $text);
return $text;
} 

 

Bet kā lai atgriež to uz otru pusi lai spētu pieprasīt no php,mysql konkrētu informāciju.

Ir doma pievienot kaut kādu skaitli galā vai sākuma ,bet nebūs diezko smuki ,varbūt ir kādi gatavi, labāki varianti?

Link to comment
Share on other sites

Glabā mysql'ā papildu lauku ar jau iztīrīto urli. Pēc tā tad arī meklēsi.

Vai arī urlī papildu glabā unikalās atslēgas numuru un datubāzē tad meklē pēc tā:

http://kkas.lv/123/pardosana-nonak-ea-sporta-speles

Link to comment
Share on other sites

garumzīmes labāk nevajag. es izmantoju taadu variantu:

 

<?php
function seo_string($string, $separator = '-')
{
$string = str_replace(array("ş", "Ş", "Ţ", "ţ", "ă", "î", "â"), array("s", "s", "t", "t", "a", "i", "a"), $string);  //RO translit
$string = str_replace(array("ā","č", "ē", "ģ", "ķ", "ļ", "ī", "ū", "š", "ņ", "ž"), array("a", "c", "e", "g", "k", "l", "i", "u", "s", "n", "z"), $string); //LV translit
$string =  str_replace(array("Ё","Ж","Ч","Ш","Щ","Э","Ю","Я","ё","ж","ч","ш","щ","э","ю","я","А","Б","В","Г","Д","Е","З","И","Й","К","Л","М","Н","О","П","Р","С","Т","У","Ф","Х","Ц","Ы","а","б","в","г","д","е","з","и","й","к","л","м","н","о","п","р","с","т","у","ф","х","ц","ь","ы"),array("JO","ZH","CH","SH","SCH","JE","JY","JA","jo","zh","ch","sh","sch","je","jy","ja","A","B","V","G","D","E","Z","I","J","K","L","M","N","O","P","R","S","T","U","F","H","C","Y","a","b","v","g","d","e","z","i","j","k","l","m","n","o","p","r","s","t","u","f","h","c","'","y"), $string); //RU translit
$string = strtolower($string);
$string = trim($string);
$string = trim(ereg_replace("[^ A-Za-z0-9_]", " ", $string));
#$string = ereg_replace("[ tnr]+", "-", $string);
$string = str_replace(" ", $separator, $string);
$string = ereg_replace("[ -]+", "-", $string);
return $string;
}
?>

 

 

un ID lieku vai nu priekšā vai pakaļā (pēc garastāvokļa), un neko lieku mysqlā glabāt negribu :)

Link to comment
Share on other sites

  • 4 months later...

pajautāšu tepat...

 

ir links:

http://www.kautkadalapa.lv/katalogs/101/preces-nosaukums

vēlētos uzzināt, vai ir jēga pirms sūtīšanas lietotājam pārbaudīt, vai linkā sakrīt preces id ar preces nosaukumu, vai pietiks tikai ar preces id? tb, ja id nesakrīt ar nosaukumu, tad redirektējam lietotāju uz pareizo saiti, atkarībā no padotā preces id...

 

Piemēram, atļaut vērt vaļā

http://www.kautkadalapa.lv/katalogs/101/nepareizs-preces-nosaukums

vai nē?

 

Preces nosaukums nav unikāls. Uztaisīts tā, ka pēdējā daļa nav obligāta.

http://www.kautkadalapa.lv/katalogs/101/preces-nosaukums
http://www.kautkadalapa.lv/katalogs/101/

Abi linki atvērs vienu un to pašu lappusi.

Edited by Val
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...