Dynamic Link? And how to implement? [closed]

3

I do not know the name of this technique, I am a student, but sometimes I see in the lower left corner of the chrome the complete type link ...

link

Then suddenly it changes to:

link

I'm new to the web and forgive my ignorance if it's something simple. I wanted to know what this is: /.../  and also how I make the link stay organized: / - video-game-legal.html

    
asked by anonymous 08.05.2015 / 06:14

2 answers

3

I think I understand what you mean. I made a solution in PHP, but I can use the same logic in another language. These /../ means that the URL suffers a shortening, and the content removed is where the points are. Example:

link

Could be shortened to link . This reduces the size of the "phrase" but still retains the original address by clicking on it. You can reproduce the same effect.

I created a regular expression that takes the content between the first bar and the last URL bar (% with%). After that I simply used /../ to get the REGEX result and created a new variable with the new address. With both addresses at hand (the original and the shortened), we can create a preg_match_all tag the way you want it. See the code:

<?php

// URL de exemplo
$url = "http://www.exemplo.com/categorias/jogos/veja-as-incriveis-novidades-de-2015";

// Aplica o Regex na URL
preg_match_all('/[\da-z\.-]+\/(.+)\//', $url, $url_match);

// Pega o resultado do Regex
$new_url = str_replace($url_match[1][0], "..", $url);

// Cria um elemento <a> com nossas URLs.
$element = "<a href='$url'>$new_url</a>";

// Imprime o resultado na página
echo $element;

See working on Ideone: link

In a page running PHP, the result will be this (notice that clicking on the link the original address that is opened):

<a href='http://www.exemplo.com/categorias/jogos/veja-as-incriveis-novidades-de-2015'>http://www.exemplo.com/../veja-as-incriveis-novidades-de-2015</a>
    
08.05.2015 / 22:30
2

The browser only lowers the link to be readable to the user, but the original link does not change, it's just a way to improve readability.

    
08.05.2015 / 08:07