view raw
HereToLearn HereToLearn - 6 months ago 55
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.


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