0

i am working on a wordpress website, and i am little stuck into one sitautation,

i want to store the last part of url in $variable. here below is my URL

https://jobifyinc.com/newsite/my-profile/#tab2

i want to store #tab2 in $variable

i tried the following code but it only returns me the my-profile as a last part

   global $post;
   $post_slug = $post->post_name;

anyother best and alternative option?

  • use `explode` to break the string into array and then use `end` to get the last art of array – urfusion Sep 25 '20 at 07:59
  • `$url = "https://jobifyinc.com/newsite/my-profile/#tab2"; $arr = explode("/",$url); print_r(end($arr));` – urfusion Sep 25 '20 at 08:02
  • Does this answer your question? [Get fragment (value after hash '#') from a URL in php](https://stackoverflow.com/questions/2317508/get-fragment-value-after-hash-from-a-url-in-php) – Jeto Sep 25 '20 at 08:05
  • @urfusion thats fine you manually add url in $url, but i dynamically need that url in $variable, do you have another answer – fyn matt 881 Sep 25 '20 at 09:27
  • Do you want the "last part of the URL" as per your question title, or do you really mean that you want to get the hash part of the URL if there is one, and nothing otherwise? – FluffyKitten Sep 25 '20 at 17:33

0 Answers0