HereToLearn HereToLearn - 1 year ago 94
PHP Question

PHP Outputting Data with Escape Sequences

I am trying to concatenate retrieved data from the database into a table cell and make the URL clickable.

I am using the tag with the an href attribute to achieve that, but for some reason it is not working and I'm presented with a blank table cell. Any idea why?

echo "<tr>" .
"<td>" . $historyData['Name'] . "</td>" .
"<td><a href=\"" . $historyData['URL'] . "\"/a></td>" .

Also tried

echo "<tr>" .
"<td>" . $historyData['Name'] . "</td>" .
"<td><a href="" . $historyData['URL'] . ""/a></td>" .

Thanks in advance.

Answer Source

You have an option to make a string with ' and ".

if(isset($historyData['Name']) && isset($historyData['URL'])){
  echo "<tr>" . 
         "<td>" . $historyData['Name'] . "</td>" . 
         '<td><a href="' . $historyData['URL'] . '">title</a></td>' .
} else {
  echo 'Whoops, I made a booboo with my indexes..';

Then there is also the option of doing something like this:

echo "<td><a href='{$historyData['URL']}'>title</a></td>";

Note that you require to use the not literal string, "

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download