-4
.php?id=42466#.XBEd_rihlPY 

This is the URL address of a page. The address is not on a remote server. I want to get the ID part, ie the number, which is only "42466" at this url.

  • http://php.net/manual/de/function.parse-url.php, http://php.net/manual/de/function.parse-str.php – misorude Dec 12 '18 at 14:47
  • According to your comment on the answer below, could it be that the URL was somehow URL-encoded as `.php?id=42466%23.XBEd_rihlPY` and thus the `#` gets part of the `id` parameter? – Pinke Helga Dec 12 '18 at 15:17

1 Answers1

0

You can do it by using superglobal variable $_GET. Superglobals are variables provided by PHP language to helps programmers with handle e.g. parameters in URL. They are "superglobals" because they are available in every scope in your code. In your case this:

echo $_GET['id'];

Returns you this:

42466

because the sigh # are an anchor and its not a part of the query string

piotrq
  • 96
  • 5
  • in this way "=" after what is taking. It's just a trick. result= 42466#.XBEd_rihlPY – Piketty Thoma Dec 12 '18 at 14:52
  • 1
    Welcome to **stackoverflow** (SO). Even if the question/answer is pretty simple, there might be people having no clue of PHP. SO is not a forum. An Answer should explain how the things actually work. You could explain, what $_GET is, why it is applicable in that case (request types) aso. – Pinke Helga Dec 12 '18 at 14:56
  • @PikettyThoma You did not mention that the `#...` part is received by the server. Usually the hash-ref ist evaluated by the browser as a focus target. You might have to improve your question by editing. – Pinke Helga Dec 12 '18 at 14:59
  • I do not understand why a simple but correct answer of a new contributor got one downvote. We should encourage new members to improve their answers to conform the guidelines of SO. And here we can see how the contributor has put it into practice, editing a short answer into a well formed complete answer. Well done! +1 – Pinke Helga Dec 12 '18 at 15:31
  • sorry but I really couldn't find the answer. There was no answer in the SO. The part before # is my ID. The database only has its money. With $ _GET ['id'], it takes everything after id =. It's just the number I want. – Piketty Thoma Dec 12 '18 at 16:33
  • @PikettyThoma Again: This answer and my comments already explain: The ***server should not receive*** the `#` character. Even if so, the webserver responds with an error: `400 Bad Request`. You did not provide any code in your question making it possible to locate the error. Improve your question with code snippets and better descriptions what's going on. – Pinke Helga Dec 13 '18 at 05:23