HereToLearn HereToLearn - 23 days ago 7
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>" .
"</tr>";


Also tried

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


Thanks in advance.

Answer

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>' .
       "</tr>";
} else {
  echo 'Whoops, I made a booboo with my indexes..';
  print_r($historyData);
}

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