Dynamic Link? And how to implement?

Asked

Viewed 1,183 times

3

  • 2

    You’re confused. After all, do you want to know how to generate links or how the browser status bar works? In Google Chrome, the links are displayed briefly and after a few seconds the full link is displayed in the status bar.. is just a visual feature of the browser, nothing to do with php, javascript, etc..

  • The browser just hides the core of the URL, leaving the domain and the end. When you hold the pointer over the link it appears whole. You can switch to advanced browser options.

  • I’ve seen this before and it’s nothing you guys talked about. And I know it’s related to Back-end, but I only know php so it’s no use if I don’t tag and receive the response in java. I will consider the answer useless. And it makes no sense to HIDE because facebook has GIGANTIC links and it doesn’t happen.

  • canto inferior esquerdo do chrome o link you’re talking about how the browser shows the URL. This appears on your website?

  • No, I’m talking about the /.../ that turns into /category/ usually I see turn into category, but I’ve also seen it turn into /321312/ probably ID or code of something. And it’s not a browser thing, I’m sure. It’s probably a Json, because it’s something "variable" .

  • 1

    Didn’t realize it only happens with large links?

  • @Asurakhan I am closing the question for lack of clarity. Notice that you have received three answers already, and each speaks of a different thing. It is clear that people are not understanding what you want exactly. Could you clarify, preferably by editing the question? If you need any clarification from me, just call me with @bfavaretto here in the comments.

  • /../ not if transforms for /321312/. What happens is that in some systems the path can be reduced to /../ for viewing only, but in href, src, etc. the path continues complete.

Show 3 more comments

2 answers

3


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

http://um-site-qualquer.com/categorias/tecnologia/titulo-da-pagina

Could be shortened to http://um-site-qualquer.com/../titulo-da-pagina. This reduces the size of the "phrase" but still keeps the original address by clicking on it. It is possible to reproduce the same effect.

I created a regular expression that takes the content between the first bar and the last URL bar (/../). After that I simply used the preg_match_all to get the REGEX result and create a new variable with the new address. With both addresses in hand (the original and the shortened), we can create a tag <a> 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 it working on Ideone: https://ideone.com/NEV6j6


On a page running PHP, the result will be this (notice that when you click on the link the original address that opens):

<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>

2

The browser only decreases the link to be better readable to the user, but the original link does not change, it is just a way to improve readability.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.