Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Source: http://prohardver.hu/tema/php_kerdesek_2/hsz_9694-9694.html
- /**
- *
- * $url = new url("helló világ ez az első szép url-em");
- * var_dump($url->_output);
- *
- * string(34) "hello-vilag-ez-az-elso-szep-url-em"
- */
- class url
- {
- public $_output;
- private $_str;
- private $_separator;
- /**
- *
- * @param string $str - nyers url
- * @param string $separator - szoelvalaszto karakter
- */
- public function __construct($str, $separator = "dash")
- {
- $this->_str = $str;
- $this->_separator = $separator;
- $this->url_title();
- }
- /**
- * szep url generalas
- * @return string
- */
- protected function url_title()
- {
- if ($this->_separator == 'dash') {
- $search = '_';
- $replace = '-';
- } else {
- $search = '-';
- $replace = '_';
- }
- $str = strtolower($this->_str);
- $before = array(
- "á",
- "é",
- "ő",
- "ö",
- "ó",
- "ú",
- "ű",
- "ü",
- "í"
- );
- $after = array(
- "a",
- "e",
- "o",
- "o",
- "o",
- "u",
- "u",
- "u",
- "i"
- );
- $str = str_replace($before, $after, $str);
- $trans = array(
- '&\#\d+?;' => '',
- '&\S+?;' => '',
- '\s+' => $replace,
- '[^a-z0-9\-\._]' => '',
- $replace . '+' => $replace,
- $replace . '$' => $replace,
- '^' . $replace => $replace,
- '\.+$' => ''
- );
- $str = strip_tags($str);
- foreach ($trans as $key => $val) {
- $str = preg_replace("#" . $key . "#i", $val, $str);
- }
- return $this->_output = strtolower(trim(trim(stripslashes($str)), $replace));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement