Home > database >  Open link in New Window in PHP Echo
Open link in New Window in PHP Echo

Time:04-18

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

CodePudding user response:

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>';

CodePudding user response:

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>';
  •  Tags:  
  • php
  • Related