How to display number sign # in php

  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 379
  • Loc: Canada

Post 77 days ago

I have the following link that sends data

<a href="example.php?link=#">Link #</a><br>

I then want to show that the link was pressed:

Code: [ Select ]
if($_GET['link']=="")
    {
     //Do Nothing
    }
    else
    {
     $num = $_GET['link'];
     echo "You have pressed Link :".$num; 
    }
  1. if($_GET['link']=="")
  2.     {
  3.      //Do Nothing
  4.     }
  5.     else
  6.     {
  7.      $num = $_GET['link'];
  8.      echo "You have pressed Link :".$num; 
  9.     }


For digits digits 0 and 1 to 9, it works perfectly.
For the * character it also works.

However when I use the character #, nothing happens.
It does not even display You have pressed Link, displays absolutely nothing

I have tried the html entities but cannot seem to get them to work also

Can someone help me here so I can display the # symbol

Thanks
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9128
  • Loc: Seattle, WA

Post 75 days ago

I would substitute another character for the # sign. With URLs the # sign is treated differently so that you can scroll quickly to an anchor point that you define on the page.
  • PolishHurricane
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1587

Post 48 days ago

Yeah when using HTTP GET you have to replace it with url-encoding (I think "%23") and then urldecode() it on the backend with something like urldecode($_GET['link']), otherwise it's not going to work, just like if you tried to start passing question marks via the GET method.
  • Liamw411
  • Beginner
  • Beginner
  • Liamw411
  • Posts: 44
  • Loc: United Kingdom

Post 45 days ago

In a url the # symbol is treated as a fragment, which is used as an anchor point to skip to a certain point on a page as Bigwebmaster said. This information is only client side and not really sent to the server. As this information is only client side you could use some ajax and request the information afterwards. But as a quick solution I would just do something like this.

Code: [ Select ]
<?php
if($_GET['link']=="")
{
//Do Nothing
}
else
{
$num = $_GET['link'];
if($num=="hash"){$num="#";}else{}
echo "You have pressed Link :".$num;
}
?>
  1. <?php
  2. if($_GET['link']=="")
  3. {
  4. //Do Nothing
  5. }
  6. else
  7. {
  8. $num = $_GET['link'];
  9. if($num=="hash"){$num="#";}else{}
  10. echo "You have pressed Link :".$num;
  11. }
  12. ?>


and change your link to

Code: [ Select ]
http://yoururl/yourpage.php?link=hash

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 34 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2017. Ozzu® is a registered trademark of Unmelted, LLC.