{"id":8,"date":"2013-10-24T23:12:15","date_gmt":"2013-10-24T23:15:17","guid":{"rendered":"https:\/\/66f5bseo-softwareCustom.png"},"modified":"2015-07-16T18:03:39","modified_gmt":"2015-07-17T00:03:39","slug":"funcion-urls-amigables-con-php","status":"publish","type":"post","link":"https:\/\/emanuelpaxtian.com\/blog\/funcion-urls-amigables-con-php\/","title":{"rendered":"Funcion URLs amigables  con php"},"content":{"rendered":"<p>&iquest;Que es una URL amigable? Es facil. Tradicionalmente, cuando solicitamos a una pagina que nos muestre una determinada informaci&oacute;n, lo que hacemos es asignar una serie de valores a una serie de variables. Estas variables son pasadas a la p&aacute;gina a traves de la URL, la pagina las lee, procesa y muestra la informaci&oacute;n solicitada.<\/p>\n<p>una url no amigable<\/p>\n<blockquote>\n<p>http:\/\/dominio.com\/vernota.php?cat=php&#038;nota=23<\/p>\n<\/blockquote>\n<p>url amigable&nbsp;<\/p>\n<blockquote>\n<p>http:\/\/dominio.com\/php\/url_amigable\/<\/p>\n<\/blockquote>\n<p>sin mas aqui la funcion<\/p>\n<pre class=\"brush: php\">function amigable($id,$url) {\r\n\t\/\/ everything to lower and no spaces begin or end\r\n\t$a = array('&Agrave;', '&Aacute;', '&Acirc;', '&Atilde;', '&Auml;', '&Aring;', '&AElig;', '&Ccedil;', '&Egrave;', '&Eacute;', '&Ecirc;', '&Euml;', '&Igrave;', '&Iacute;', '&Icirc;', '&Iuml;', '&ETH;', '&Ntilde;', '&Ograve;', '&Oacute;', '&Ocirc;', '&Otilde;', '&Ouml;', '&Oslash;', '&Ugrave;', '&Uacute;', '&Ucirc;', '&Uuml;', '&Yacute;', '&szlig;', '&agrave;', '&aacute;', '&acirc;', '&atilde;', '&auml;', '&aring;', '&aelig;', '&ccedil;', '&egrave;', '&eacute;', '&ecirc;', '&euml;', '&igrave;', '&iacute;', '&icirc;', '&iuml;', '&ntilde;', '&ograve;', '&oacute;', '&ocirc;', '&otilde;', '&ouml;', '&oslash;', '&ugrave;', '&uacute;', '&ucirc;', '&uuml;', '&yacute;', '&yuml;', '\u00c4\u20ac', '\u00c4\u0081', '\u00c4\u201a', '\u00c4\u0192', '\u00c4\u201e', '\u00c4\u2026', '\u00c4\u2020', '\u00c4\u2021', '\u00c4\u02c6', '\u00c4\u2030', '\u00c4\u0160', '\u00c4\u2039', '\u00c4\u0152', '\u00c4\u008d', '\u00c4\u017d', '\u00c4\u008f', '\u00c4\u0090', '\u00c4\u2018', '\u00c4\u2019', '\u00c4\u201c', '\u00c4\u201d', '\u00c4\u2022', '\u00c4\u2013', '\u00c4\u2014', '\u00c4\u02dc', '\u00c4\u2122', '\u00c4\u0161', '\u00c4\u203a', '\u00c4\u0153', '\u00c4\u009d', '\u00c4\u017e', '\u00c4\u0178', '\u00c4\u00a0', '\u00c4\u00a1', '\u00c4\u00a2', '\u00c4\u00a3', '\u00c4\u00a4', '\u00c4\u00a5', '\u00c4\u00a6', '\u00c4\u00a7', '\u00c4\u00a8', '\u00c4\u00a9', '\u00c4\u00aa', '\u00c4\u00ab', '\u00c4\u00ac', '\u00c4\u00ad', '\u00c4\u00ae', '\u00c4\u00af', '\u00c4\u00b0', '\u00c4\u00b1', '\u00c4\u00b2', '\u00c4\u00b3', '\u00c4\u00b4', '\u00c4\u00b5', '\u00c4\u00b6', '\u00c4\u00b7', '\u00c4\u00b9', '\u00c4\u00ba', '\u00c4\u00bb', '\u00c4\u00bc', '\u00c4\u00bd', '\u00c4\u00be', '\u00c4\u00bf', '\u00c5\u20ac', '\u00c5\u0081', '\u00c5\u201a', '\u00c5\u0192', '\u00c5\u201e', '\u00c5\u2026', '\u00c5\u2020', '\u00c5\u2021', '\u00c5\u02c6', '\u00c5\u2030', '\u00c5\u0152', '\u00c5\u008d', '\u00c5\u017d', '\u00c5\u008f', '\u00c5\u0090', '\u00c5\u2018', '&OElig;', '&oelig;', '\u00c5\u201d', '\u00c5\u2022', '\u00c5\u2013', '\u00c5\u2014', '\u00c5\u02dc', '\u00c5\u2122', '\u00c5\u0161', '\u00c5\u203a', '\u00c5\u0153', '\u00c5\u009d', '\u00c5\u017e', '\u00c5\u0178', '&Scaron;', '&scaron;', '\u00c5\u00a2', '\u00c5\u00a3', '\u00c5\u00a4', '\u00c5\u00a5', '\u00c5\u00a6', '\u00c5\u00a7', '\u00c5\u00a8', '\u00c5\u00a9', '\u00c5\u00aa', '\u00c5\u00ab', '\u00c5\u00ac', '\u00c5\u00ad', '\u00c5\u00ae', '\u00c5\u00af', '\u00c5\u00b0', '\u00c5\u00b1', '\u00c5\u00b2', '\u00c5\u00b3', '\u00c5\u00b4', '\u00c5\u00b5', '\u00c5\u00b6', '\u00c5\u00b7', '&Yuml;', '\u00c5\u00b9', '\u00c5\u00ba', '\u00c5\u00bb', '\u00c5\u00bc', '\u00c5\u00bd', '\u00c5\u00be', '\u00c5\u00bf', '&fnof;', '\u00c6\u00a0', '\u00c6\u00a1', '\u00c6\u00af', '\u00c6\u00b0', '\u00c7\u008d', '\u00c7\u017d', '\u00c7\u008f', '\u00c7\u0090', '\u00c7\u2018', '\u00c7\u2019', '\u00c7\u201c', '\u00c7\u201d', '\u00c7\u2022', '\u00c7\u2013', '\u00c7\u2014', '\u00c7\u02dc', '\u00c7\u2122', '\u00c7\u0161', '\u00c7\u203a', '\u00c7\u0153', '\u00c7\u00ba', '\u00c7\u00bb', '\u00c7\u00bc', '\u00c7\u00bd', '\u00c7\u00be', '\u00c7\u00bf'); \r\n    $b = array('A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l', 'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o'); \r\n    $url= str_replace($a, $b,$url);\r\n\t$url = strtolower(trim($url));\r\n\t\/\/replace accent characters, epends your language is needed\r\n\t\/\/$url=replace_accents($url);\r\n\t\/\/ decode html maybe needed if there's html I normally don't use this\r\n\t\/\/$url = html_entity_decode($url,ENT_QUOTES,'UTF8');\r\n\t\/\/ adding - for spaces and union characters\r\n\t$find = array(' ', '&amp;', '\\r\\n', '\\n', '+',',');\r\n\t$url = str_replace ($find, '-', $url);\r\n\t\/\/delete and replace rest of special chars\r\n\t$find = array('\/[^a-z0-9\\-&lt;&gt;]\/', '\/[\\-]+\/', '\/&lt;[^&gt;]*&gt;\/');\r\n\t$repl = array('', '-', '');\r\n\t$url = preg_replace ($find, $repl, $url);\r\n\t\/\/return the friendly url\r\n\treturn $id.\"_\".$url; \r\n}\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&iquest;Que es una URL amigable? Es facil. Tradicionalmente, cuando solicitamos a una pagina que nos muestre una determinada informaci&oacute;n, lo que hacemos es asignar una serie de valores a una&hellip;<\/p>\n","protected":false},"author":1,"featured_media":642,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-8","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/emanuelpaxtian.com\/blog\/wp-json\/wp\/v2\/posts\/8","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/emanuelpaxtian.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/emanuelpaxtian.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/emanuelpaxtian.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/emanuelpaxtian.com\/blog\/wp-json\/wp\/v2\/comments?post=8"}],"version-history":[{"count":0,"href":"https:\/\/emanuelpaxtian.com\/blog\/wp-json\/wp\/v2\/posts\/8\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/emanuelpaxtian.com\/blog\/wp-json\/wp\/v2\/media\/642"}],"wp:attachment":[{"href":"https:\/\/emanuelpaxtian.com\/blog\/wp-json\/wp\/v2\/media?parent=8"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/emanuelpaxtian.com\/blog\/wp-json\/wp\/v2\/categories?post=8"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/emanuelpaxtian.com\/blog\/wp-json\/wp\/v2\/tags?post=8"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}