0

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?

1

2 Answers 2

4

Use urlencode()

$opCode = urlencode('TCP Y'); echo "<td><a href=http://www.smstoneta.com/show.php?opcode=".$opCode.">".$row['num_y']."</a></td>"; 
Sign up to request clarification or add additional context in comments.

Comments

1

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>"; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.