Amit Swain
Amit Swain

Reputation: 313

space is neglected when passed a string by URL

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

Answers (2)

DaneSoul
DaneSoul

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

Joao
Joao

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

Related Questions