Retrieve original value of a chain already converted to friendly url

0

I am making a friendly url through the "title" fields of each table, for example Home, The art of writing, Web development that using this function for the friendly url would look like this:

<?php 

function seo_url($cadena){
    $cadena= utf8_decode($cadena);
    $cadena = str_replace(' ', '-', $cadena);
    $cadena = str_replace('?', '', $cadena);
    $cadena = str_replace('+', '', $cadena);
    $cadena = str_replace(':', '', $cadena);
    $cadena = str_replace('??', '', $cadena);
    $cadena = str_replace(''', '', $cadena);
    $cadena = str_replace('!', '', $cadena);
    $cadena = str_replace('¿', '', $cadena);
    $originales = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûýýþÿ??';
    $modificadas = 'aaaaaaaceeeeiiiidnoooooouuuuybsaaaaaaaceeeeiiiidnoooooouuuyybyRr';
    $cadena = strtr($cadena, utf8_decode($originales), $modificadas);

    $cadena_minuscula = strtolower($cadena);

    return $cadena_minuscula;

}

//Título url amigable
$paginaUrl = seo_url($value["title"]);  
echo '<li class=""><a href="'.$paginaUrl.'" class="">'.$value["title"].'</a><i class="fa fa-circle" aria-hidden="true"></i></li>';

?>

Then these links would be sent like this for the url:

<li class=""><a href="inicio" class="">Inicio</a><i class="fa fa-circle" aria-hidden="true"></i></li>
<li class=""><a href="el-arte-de-escribir" class="">El arte de escribir</a><i class="fa fa-circle" aria-hidden="true"></i></li>
<li class=""><a href="desarrollo-web" class="">Desarrollo web</a><i class="fa fa-circle" aria-hidden="true"></i></li>

The page that collects the value of the url with Get then receives it by the encoded value - > $ paginaUrl and when I check it I do it for two fields:

$item = "title";//Campo de la tabla páginas a consultar.
$valor = $_GET["ruta"];//Valor que viene en la url para comprobar en el campo $item de la tabla.

if(isset($_GET["ruta"])){
     $valor = $_GET["ruta"];
}

Then when checking the table the "title" field does not exist as I am sending the amiable url (seo_url)

The test .htaccess would look like this:

RewriteRule ^([-a-zA-Z0-9/]+)$ index.php?ruta=$1

I know that if I also send the "id" of each title I could do it in another way or even by increasing the parameters in the .htaccess but my question is:

Would it be possible to recover the original value of the string before being friendly to resend as a title? That is, re-pass or retrieve "the-art-of-writing" to the original title - & "The art of writing" to do the checks on each table by "title".

I know it would also be possible to do it with your id or even create a "route" field in each table and do the check for that "route" instead of "title" but for now I would like to see if it is possible to do the option to recover the original.

Greetings.

    
asked by José Carlos - kahlito 23.03.2018 в 15:48
source

0 answers