I have a message that I would like to show by using alert()
$message = "No result found for the following info:Name: ".$FullName."IC: ".$ID." in database.";
echo "<script>alert('".$message."'); window.history.back();</script>";
This is working but if I add a new line '\\n' into the message
$message = "No result found for the following info:\nName: ".$FullName."\nIC: ".$ID." in database.";
it will not show out the pop out message. What is the problem?
Edit it to not change to newline in PHP, instead in javascript:
'No result found for the following info:\nName: '.$FullName.'\nIC: '.$ID.' in database.'
^ ^ ^ ^ ^ ^
OR by adding extra backslash: "\\\\n"
.
According to Panther, also truth: use 'alert("' . $message . '")'
.
Add another \\
backslash on your newlines:
$message = "No result found for the following info:\\nName: ".$FullName."\\nIC: ".$ID." in database.";
或者使用 PHP_EOL
$msg = 'Hello' . PHP_EOL . 'Next line';
\\n
etc. aren't interpreted in single quotes, just in double quotes.
echo "<script>alert(\"" . $message . "\"); window.history.back();</script>";
OR
echo '<script>alert("' . $message . '"); window.history.back();</script>';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.