nmm
nmm

Reputation: 117

How to make PHP get special characters like "&" from the URL link

Need some help here....

<a href='Delete.php?id=$itemid'>Delete</a>
$itemid=$_GET["id"];
echo $itemid;

The code is able to grab the id from the previous link to the next page but once it encounter special id like "m&b". It is not able to read the "&" character. What can I do? I echo the itemid to check and php only get the character "m" and not the whole.

Upvotes: 1

Views: 932

Answers (1)

vimuth
vimuth

Reputation: 5612

Think this will work

<a href='Delete.php?id=<?php echo urlencode($itemid); ?>'>Delete</a>

Then you can use urldecode() to decode.

$itemid=urldecode($_GET["id"]);
echo $itemid;

urlencode function encodes the url string to be used in a query part of a URL, as a convenient way to pass variables to the next page.

Upvotes: 1

Related Questions