更新时间:2023-12-04 13:14:28
我整理我的问题。该解决方案是多次提到的组合。我拿来从表中的记录,并把(BR)的含量
$ tagdetailstoprint = $行['print_tag_details'];
$符= nl2br($ tagdetailstoprint);
$文字= str_replace函数($符\ r \ N,$ tagdetailstoprint);
在我的textarea,我这样做:
< TextArea类=表单控制ID =details_input_<?PHP的echo $ printid;>中行=8> <?PHP的回声用htmlspecialchars($文本); ?>< / textarea的>
和风格,我加的,并建议样式表
<风格>
。文本{
空格:pre系列;
}
< /风格>
在我的文件更新打印标签-edit.php的,我这样做:
$细节= nl2br($ _ POST ['printdetails']); //我存储在nl2br在我的MySQL表
这code是创建的文本文件:
$今天=日期(Y-M-D-Hi的);
标题(内容类型:应用程序/八位字节流);
标题(内容处置:附件;文件名=$今天_为Backup.txt);
$查询=SELECT * FROM tagto_print,其中print_tag_id ='8';
$结果= mysql_query($查询);
$数据=;
$场所=阵列(&所述峰; br />中,&所述峰; br>中,&所述峰; br />中); //我把BR阵
而($行= mysql_fetch_object($结果)){
$文字= str_replace函数($符\ r \ N,$行向> print_tag_details); //并条代替它与\ r \ N
。$数据={$文字};
。$数据=\ r \ N的;
}
回声$的数据;
出口;
}
I have some text stored in mysql table in below format:
but, when I update any line in the text area, it displays the below output.Actually, I'm trying to make a text file with this if I don't update it to output me the above content in a text file but, When I update the content to give me the below output in the text file.
Here is my code:
This is the demo line 1 This is the demo line 2This is the demo line 3This is the demo line 4This is the demo line 5
<table>
<tr class="head">
<th style="display: none">Lable Name</th>
<th style="display: none">Tag Details</th>
</tr>
<?php
$sql1 = "SELECT * from tagto_print where print_tag_id='8'";
$reslabel=mysql_query($sql1);
$i=1;
while($row=mysql_fetch_array($reslabel))
{
$printid=$row['print_tag_id'];
$tagdetailstoprint=$row['print_tag_details'];
?>
<tr id="<?php echo $printid; ?>" class="edit_tr">
<td width="10%"><?php echo $row['print_tag_labelname'];?></td>
<td width="50%" class="edit_td">
<span id="details_<?php echo $printid; ?>" class="text"><pre><?php echo $tagdetailstoprint; ?></pre></span>
<textarea class="form-control" id="details_input_<?php echo $printid; ?>" rows="8"> <?php echo $tagdetailstoprint; ?></textarea></td>
</tr>
<?php
$i++;
}
?>
</table>
<style>
.form-control
{
display:none;
}
</style>
<script type="text/javascript">
$(document).ready(function()
{
$(".edit_tr").click(function()
{
var ID=$(this).attr('id');
$("#details_"+ID).hide();
$("#details_input_"+ID).show();
}).change(function()
{
var ID=$(this).attr('id');
var tagdetailsarea=$("#details_input_"+ID).val();
var dataString = 'printid='+ ID +'&printdetails='+tagdetailsarea;
$("#details_"+ID).html('<img src="load.gif" />');
if(tagdetailsarea.length>0)
{
$.ajax({
type: "POST",
url: "print-tags-edit.php",
data: dataString,
cache: false,
success: function(html)
{
$("#details_"+ID).html(tagdetailsarea);
}
});
}
else
{
alert('You can not Print Blank Data');
}
});
$(".form-control").mouseup(function()
{
return false
});
$(document).mouseup(function()
{
$(".form-control").hide();
$(".text").show();
});
});
</script>
File to update print-tags-edit.php:
<?php
if($_POST['printid'])
{
$id=$_POST['printid'];
$details=$_POST['printdetails'];
$sql = "update tagto_print set print_tag_details='$details' where print_tag_id='$id'";
mysql_query($sql);
}
?>
I sorted my problem. This solution is mix of many references. I fetched the record from the table and put the (br) in content
$tagdetailstoprint=$row['print_tag_details'];
$breaks = nl2br($tagdetailstoprint);
$text = str_replace($breaks, "\r\n", $tagdetailstoprint);
In my textarea, I did this:
<textarea class="form-control" id="details_input_<?php echo $printid; ?>" rows="8"> <?php echo htmlspecialchars($text); ?></textarea>
and in style, I added the style sheet suggested by the AND
<style>
.text{
white-space: pre-line;
}
</style>
In my file to update print-tags-edit.php, I did this:
$details=nl2br($_POST['printdetails']); // i stored the nl2br in my mysql table
This code is to create the text file:
$today = date("Y-m-d-Hi");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=".$today."_Backup.txt");
$query = "SELECT * FROM tagto_print where print_tag_id='8'";
$result = mysql_query($query);
$data = "";
$breaks = array("<br />","<br>","<br/>"); // i put the br in array
while ($row=mysql_fetch_object($result)) {
$text = str_replace($breaks, "\r\n", $row->print_tag_details); // and repalced it with the "\r\n"
$data .= "{$text}";
$data .="\r\n";
}
echo $data;
exit;
}