我的PHP出了问题。在我的代码中,它显示文本<?php if (!empty()) { echo ; } ?>
在运行脚本时显示在文本框的值中。我不想删除值中的文本,因为我需要在打开弹出窗口时使用它们从变量$email_str
输入字符串列表,这样我就可以在文本框中输出字符串列表
以下是代码:
<?php
include('config.php');
if($_GET['id'] != '')
{
$id = $_GET['id'];
$readDateTime = date("Y-m-d h:i:s");
mysql_query("update tracker set isRead='1', readDateTime='$readDateTime' where id='$id'");
header('Location: http://robsite.com/phpmailer/examples/blank.jpg');
exit;
}
else
{
echo "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title>Send Email</title>
<link type='text/css' rel='stylesheet' href='style.css' />
<script src='jquery-1.12.0.js'></script>
<script>
$(document).ready(function(){
$('#popup').click(function(event) {
event.preventDefault();
var popup = window.open('add_address.php', '_blank', 'toolbar=yes, scrollbars=yes, resizable=yes, top=100, left=500, width=400, height=400');
if (popup != null && !popup.closed) {
var element = popup.document.getElementById('thePopupField');
var text = $('#theField').val();
if(text != ''){
var count = (text.match(/,/g) || []).length;
popup.my_count = count+1;
popup.my_special_setting = text.replace(/,/g, '\n');
}
}
});
});
</script>
</head>
<body>
<!---->
<form action='pr_send.php' method='POST' id='theForm'>
<table>
<!-- <tr>
<td>From:</td>
<td><input type='text' name='from'></td>
</tr> -->
<tr>
<td><input type='button' name='to' value='' style='height:24px; width:24px; background: url(\"addressbook.png\"); border:none;' id='popup' > To:</td> <!--onClick='Popup()'-->
<td><input type='text' id='theField' name='to' value='<?php if (!empty($email_str)) { echo $email_str; } ?>' style='height:15px; width:650px'> (<span id='noOfEmails'>0</span>)</td>
</tr>
<tr>
<td>Subject:</td>
<td><input type='text' name='subject' style='height:15px; width:650px'></td>
</tr>
<tr>
<td>Message:</td>
<td><textarea name='message' cols='90' rows='20'></textarea></td>
</tr>
<tr>
<td colspan='2' align='left'>
<input type='submit' name='send' value='' style='height:35px; width:100px; background: url(\"send.png\"); border:none'>
</td>
</tr>
</table>
</form>
</body>
<!--<script type='text/javascript'>
var popup = null;
function Popup()
{
window.open('add_address.php', '_blank', 'toolbar=yes, scrollbars=yes, resizable=yes, top=100, left=500, width=400, height=400');
}
function closePopUp()
{
if (popup)
{
popup.close();
}
}
</script>-->
</html>";
}
if (!empty($_POST['message']))
{
$emails = explode("\n", $_POST['message']); // explode textarea on a line break into an array
$email_str = implode(", ", $emails); // take each of the emails and implode together with the ,
echo '<script> closePopUp(); </script>'; //call javascript function
}
?>
当我在HTML中运行代码时,它可以正常工作,因为文本没有显示在文本框中。
当我在PHP中运行html代码时,如何隐藏值中的文本?
答案 0 :(得分:0)
问题是您在使用echo
打印的字符串中包含PHP标记。因此,通过建议的修复,您将执行PHP代码并将其连接到要打印的HTML字符串。
<?php
include('config.php');
if($_GET['id'] != '')
{
$id = $_GET['id'];
$readDateTime = date("Y-m-d h:i:s");
mysql_query("update tracker set isRead='1', readDateTime='$readDateTime' where id='$id'");
header('Location: http://robsite.com/phpmailer/examples/blank.jpg');
exit;
}
else
{
$email = !empty($email_str) ? $email_str : "";
$html = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title>Send Email</title>
<link type='text/css' rel='stylesheet' href='style.css' />
<script src='jquery-1.12.0.js'></script>
<script>
$(document).ready(function(){
$('#popup').click(function(event) {
event.preventDefault();
var popup = window.open('add_address.php', '_blank', 'toolbar=yes, scrollbars=yes, resizable=yes, top=100, left=500, width=400, height=400');
if (popup != null && !popup.closed) {
var element = popup.document.getElementById('thePopupField');
var text = $('#theField').val();
if(text != ''){
var count = (text.match(/,/g) || []).length;
popup.my_count = count+1;
popup.my_special_setting = text.replace(/,/g, '\n');
}
}
});
});
</script>
</head>
<body>
<!---->
<form action='pr_send.php' method='POST' id='theForm'>
<table>
<!-- <tr>
<td>From:</td>
<td><input type='text' name='from'></td>
</tr> -->
<tr>
<td><input type='button' name='to' value='' style='height:24px; width:24px; background: url(\"addressbook.png\"); border:none;' id='popup' > To:</td> <!--onClick='Popup()'-->
<td><input type='text' id='theField' name='to' value='".$email."' style='height:15px; width:650px'> (<span id='noOfEmails'>0</span>)</td>
</tr>
<tr>
<td>Subject:</td>
<td><input type='text' name='subject' style='height:15px; width:650px'></td>
</tr>
<tr>
<td>Message:</td>
<td><textarea name='message' cols='90' rows='20'></textarea></td>
</tr>
<tr>
<td colspan='2' align='left'>
<input type='submit' name='send' value='' style='height:35px; width:100px; background: url(\"send.png\"); border:none'>
</td>
</tr>
</table>
</form>
</body>
<!--<script type='text/javascript'>
var popup = null;
function Popup()
{
window.open('add_address.php', '_blank', 'toolbar=yes, scrollbars=yes, resizable=yes, top=100, left=500, width=400, height=400');
}
function closePopUp()
{
if (popup)
{
popup.close();
}
}
</script>-->
</html>";
echo $html;
}
if (!empty($_POST['message']))
{
$emails = explode("\n", $_POST['message']); // explode textarea on a line break into an array
$email_str = implode(", ", $emails); // take each of the emails and implode together with the ,
echo '<script> closePopUp(); </script>'; //call javascript function
}
?>
答案 1 :(得分:0)
您将HTML页面构建为PHP字符串,但您尝试在该PHP字符串中包含PHP代码。
PHP在服务器端运行,而不是在客户端运行。如果您将PHP代码作为文本发送到客户端,它将被忽略。
此外,在您使用过之前,您不会给$ email_str一个值。
在使用之前移动代码将$ email_str设置为,如果POST数据不存在,也将其设置为默认值“”。
然后,对于你的回声,将它分成3部分:
码
layout_width