Jump to content

Recommended Posts

Hi,

I have in column "keywords" comma separated keywords in one row/news. Example in ID "1" in column "keywords" have: "Šport, Fudbal, Četvrta Liga". I want to make a tag-s from those words to be like: http://site.com/tag/sporthttp://site.com/tag/fudbal, http://site.com/tag/cetvrta-liga.

At first I separate those words by:

$input = $vest_keywords;
$removed_spaces = preg_replace('/\s*,\s*/', ',', $input);
$output = explode(',', $removed_spaces);
foreach($output as $tags) {
  echo $tags;
}

This give me: Šport | Fudbal | Četvrta liga

 

But I have a "slug-maker", and I have a problem with redeclare.

/* SLUG */
$string = $output;
  function my_str_split($string) {
    $slen = strlen($string);
    for ($i = 0; $i < $slen; $i++) {
      $sArray[$i] = $string{$i};
    }
    return $sArray;
  }
  function noDiacritics($string) {
    //cyrylic transcription
    $cyrylicFrom = array('А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ъ', 'Ы', 'Ь', 'Э', 'Ю', 'Я', 'а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ъ', 'ы', 'ь', 'э', 'ю', 'я');
    $cyrylicTo = array('A', 'B', 'W', 'G', 'D', 'Ie', 'Io', 'Z', 'Z', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'F', 'Ch', 'C', 'Tch', 'Sh', 'Shtch', '', 'Y', '', 'E', 'Iu', 'Ia', 'a', 'b', 'w', 'g', 'd', 'ie', 'io', 'z', 'z', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'f', 'ch', 'c', 'tch', 'sh', 'shtch', '', 'y', '', 'e', 'iu', 'ia');
    $from = array("Á", "À", "Â", "Ä", "Ă", "Ā", "Ã", "Å", "Ą", "Æ", "Ć", "Ċ", "Ĉ", "Č", "Ç", "Ď", "Đ", "Ð", "É", "È", "Ė", "Ê", "Ë", "Ě", "Ē", "Ę", "Ə", "Ġ", "Ĝ", "Ğ", "Ģ", "á", "à", "â", "ä", "ă", "ā", "ã", "å", "ą", "æ", "ć", "ċ", "ĉ", "č", "ç", "ď", "đ", "ð", "é", "è", "ė", "ê", "ë", "ě", "ē", "ę", "ə", "ġ", "ĝ", "ğ", "ģ", "Ĥ", "Ħ", "I", "Í", "Ì", "İ", "Î", "Ï", "Ī", "Į", "IJ", "Ĵ", "Ķ", "Ļ", "Ł", "Ń", "Ň", "Ñ", "Ņ", "Ó", "Ò", "Ô", "Ö", "Õ", "Ő", "Ø", "Ơ", "Œ", "ĥ", "ħ", "ı", "í", "ì", "i", "î", "ï", "ī", "į", "ij", "ĵ", "ķ", "ļ", "ł", "ń", "ň", "ñ", "ņ", "ó", "ò", "ô", "ö", "õ", "ő", "ø", "ơ", "œ", "Ŕ", "Ř", "Ś", "Ŝ", "Š", "Ş", "Ť", "Ţ", "Þ", "Ú", "Ù", "Û", "Ü", "Ŭ", "Ū", "Ů", "Ų", "Ű", "Ư", "Ŵ", "Ý", "Ŷ", "Ÿ", "Ź", "Ż", "Ž", "ŕ", "ř", "ś", "ŝ", "š", "ş", "ß", "ť", "ţ", "þ", "ú", "ù", "û", "ü", "ŭ", "ū", "ů", "ų", "ű", "ư", "ŵ", "ý", "ŷ", "ÿ", "ź", "ż", "ž");
    $to = array("A", "A", "A", "AE", "A", "A", "A", "A", "A", "AE", "C", "C", "C", "C", "C", "D", "D", "D", "E", "E", "E", "E", "E", "E", "E", "E", "G", "G", "G", "G", "G", "a", "a", "a", "ae", "ae", "a", "a", "a", "a", "ae", "c", "c", "c", "c", "c", "d", "d", "d", "e", "e", "e", "e", "e", "e", "e", "e", "g", "g", "g", "g", "g", "H", "H", "I", "I", "I", "I", "I", "I", "I", "I", "IJ", "J", "K", "L", "L", "N", "N", "N", "N", "O", "O", "O", "OE", "O", "O", "O", "O", "CE", "h", "h", "i", "i", "i", "i", "i", "i", "i", "i", "ij", "j", "k", "l", "l", "n", "n", "n", "n", "o", "o", "o", "oe", "o", "o", "o", "o", "o", "R", "R", "S", "S", "S", "S", "T", "T", "T", "U", "U", "U", "UE", "U", "U", "U", "U", "U", "U", "W", "Y", "Y", "Y", "Z", "Z", "Z", "r", "r", "s", "s", "s", "s", "ss", "t", "t", "b", "u", "u", "u", "ue", "u", "u", "u", "u", "u", "u", "w", "y", "y", "y", "z", "z", "z");
    $from = array_merge($from, $cyrylicFrom);
    $to = array_merge($to, $cyrylicTo);
    $newstring = str_replace($from, $to, $string);
    return $newstring;
  }
  function makeSlugs($string, $maxlen = 0) {
    $newStringTab = array();
    $string = strtolower(noDiacritics($string));
    if (function_exists('str_split')) {
      $stringTab = str_split($string);
    } else {
      $stringTab = my_str_split($string);
    }
    $numbers = array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-");
    //$numbers=array("0","1","2","3","4","5","6","7","8","9");
    foreach ($stringTab as $letter) {
      if (in_array($letter, range("a", "z")) || in_array($letter, $numbers)) {
        $newStringTab[] = $letter;
      } elseif ($letter == " ") {
        $newStringTab[] = "-";
      }
    }
    if (count($newStringTab)) {
      $newString = implode($newStringTab);
      if ($maxlen > 0) {
        $newString = substr($newString, 0, $maxlen);
      }
      $newString = removeDuplicates('--', '-', $newString);
    } else {
      $newString = '';
    }
    return $newString;
  }
  function checkSlug($sSlug) {
    if (preg_match("/^[a-zA-Z0-9]+[a-zA-Z0-9\-]*$/", $sSlug) == 1) {
      return true;
    }
    return false;
  }
  function removeDuplicates($sSearch, $sReplace, $sSubject) {
    $i = 0;
    do {
      $sSubject = str_replace($sSearch, $sReplace, $sSubject);
      $pos = strpos($sSubject, $sSearch);
      $i++;
      if ($i > 100) {
        die('removeDuplicates() loop error');
      }
    } while ($pos !== false);
    return $sSubject;
  }
  $vesti_tag_slug = makeSlugs($string, $maxlen = '0');
  /* /. SLUG */

So I want to have tags like: sport | fudbal | cetvrta-liga

Can You help how can I get the links that You se above?

Thanks in advanced!

T

Link to comment
https://forums.phpfreaks.com/topic/312618-tag-s-comma-separated-to-slug/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.