Reputation: 313
I am using the following code to display a hyperlink inside a table:
echo "<td><a href=http://www.smstoneta.com/show.php?opcode=TCP Y".">".
$row['num_y']."</a></td>";
The hyperlink is displayed successfully but when I click on the hyperlink, the URL is
www.smstoneta.com/show.php?opcode=TCP
instead of
www.smstoneta.com/show.php?opcode=TCP Y
Why am I not getting the full URL?
Upvotes: 0
Views: 80
Reputation: 4511
You need URL Encode spaces to make them working in links.
Here is manual for PHP function urlencode
$safe_url = urlencode('http://www.smstoneta.com/show.php?opcode=TCP Y');
echo "<td><a href=" .$safe_url. ">" .$row['num_y']. "</a></td>";
BTW, more readable (no concatenation needed) version to echo such strings is:
echo "<td><a href='{$safe_url}'>{$row['num_y']}</a></td>";
Upvotes: 1
Reputation: 2746
Use urlencode()
$opCode = urlencode('TCP Y');
echo "<td><a href=http://www.smstoneta.com/show.php?opcode=".$opCode.">".$row['num_y']."</a></td>";
Upvotes: 4