Get anchor url with PHP

3

I need to get the data of an anchor in the url, follow link:

link

I need this ID 8 that is in the anchor, the problem is that I can not use Javascript to get it.

I need to use only PHP.

I'm using Codeigniter, however, if I use $this->uri->segment() , it does not recognize the anchor as a segment.

    
asked by anonymous 28.06.2016 / 22:10

2 answers

3

This is not possible. Since this value is never sent to the server, it will not be available in $_SERVER['REQUEST_URI'] or similar predefined variables.

You would need some kind of "magic" on the client side (for example, using Javascript) to pass this value to PHP.

The original response was taken from SOEN

One of the possible solutions would be to use Ajax or passing the desired value to a url parameter as well.

Leaving your url with something like this:

http://192.168.110.4/jornal/1-jornal1?id=5#8

Why not? So you would meet Javascript and PHP.

    
28.06.2016 / 22:27
-2

It seems to me that each segment is divided by '/', so it is normal for it not to recognize '#' as a segment delimiter.

The following should work. First extract the segment and then isolate the id you want.

$segment = $this->uri->segment(2); //obter o segmento
preg_match("/#([0-9]*)/", $segment, $matches); //isolar o id
$id = !empty($matches[1]) ? (int) $matches[1] : null; // verificar se este existe
    
28.06.2016 / 22:22