0

How to open link in new window if the output using echo''? I've tried this method https://stackoverflow.com/a/15766254/13981642 but cannot show the output using echo'';

My PHP Code: echo 'Last Revision: ' . date('F j, Y', strtotime($row['updated_at'])) . '<a href="http://example.com/contact.php">Contact us</a>';

Thank you

Haqem
  • 11
  • 3

2 Answers2

0

The method to which you linked works perfectly well when you escape the quotes properly as shown below with a simple echo and an alternative printf statement.

Notice that the single quotes within the output string are escaped using a backslash!

$row['updated_at']='2022/03/20 08:32:12';
$date=date( 'F j, Y', strtotime( $row['updated_at'] ) );

printf(
    'Last Revision: %s <a href="//example.com/contact.php" onclick="window.open(\'/contact.php\',\'Contact\',\'width=800,height=600\'); return false">Contact us</a>', 
    $date
);


echo 'Last Revision: '.$date.' <a href="//example.com/contact.php" onclick="window.open(\'/contact.php\',\'Contact\',\'width=800,height=600\'); return false">Contact us</a>';
Professor Abronsius
  • 33,063
  • 5
  • 32
  • 46
  • It's worked thank you. I've another question how to make injection PHP in link tag after contact.php?feedback='. $row['page_id'] .' ? – Haqem Apr 18 '22 at 09:16
0

Add target="_BLANK" in an anchor tag it will redirect to new tab

My PHP Code: echo 'Last Revision: ' . date('F j, Y', strtotime($row['updated_at'])) . '<a target="_BLANK" href="http://example.com/contact.php">Contact us</a>';
Paresh
  • 16
  • 2