0

I am trying to add hyperlink to a variable in the body of the table in a row. this is what I have right now:

echo "<td>"<a target='_blank' href="'http://alpha.bug.corp.com/show_bug.cgi?id=$ticket_id'"> .$ticket_id. </a>"</td>";

Without adding the hyperlink part when I just print out the variable...it prints out fine. I guess I am missing something in the syntax to make it work.

Thank you in advance!

2 Answers 2

3

You're missing the concatenation operator . and you've got your quotes mixed up:

echo "<td><a target='_blank' href='http://alpha.bug.corp.com/show_bug.cgi?id=" . $ticket_id . "'>" . $ticket_id . "</a></td>";

To be clear, using double quotes you can leave your variables inside them, but I personally don't like doing it. Variables inside double quotes will be interpreted and parsed by PHP. This would work fine too:

echo "<td><a target='_blank' href='http://alpha.bug.corp.com/show_bug.cgi?id=$ticket_id'>$ticket_id</a></td>";

You could do this:

echo "<td>" . "<a href...

...but it's pointless in almost all cases except where you want to switch to the other type of quote. You might do this so you don't have to escape quotes, or so that variables will (double quotes) or won't (single quotes) be parsed in certain segments.

echo "<td>" . '<a href="">I can use double quotes now!</a>' . "</td>";

Another common use would be for new lines in a <pre> block where \n characters are not processed inside single quotes:

echo 'Your test is going here, Mary said: "Hello Bob!"' . "\n";
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! Works now. I also prefer the second option...was working along that option only...I had the <td> quotes as an extra which was causing it to break. After seeing some blogs...I thought it may be the concatenation operator :)
0

Try this

echo '<td><a target="_blank" href="http://alpha.bug.corp.com/show_bug.cgi?id=' . $ticket_id . '">' . $ticket_id . '</a></td>';

Just write the variable out exactly have you have done for the link content. All your singles quotes and double quotes were mixed up as well

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.