简体   繁体   English

回声添加 <br> 默认情况下是什么原因?

[英]Echo adds <br> by default, what would be the cause?

jquery jQuery的

$('registration').click(function() {
       $.post('check_code.php',
        {lemail:$('input#pro_id').val(),ccode:$('input#ccode').val()},function(result){
        alert(result+"hello");
    });     
});

check_code.php check_code.php

 <?php session_start();

 include("configure.php");

$email =  $_POST['lemail'];
$ccode  =  $_POST['ccode'];

 echo $email; ?>

The php file echoes with a new line I guess <br /> tag, when I alert I get this as output: php文件以新行回显,我猜是<br />标签,当我发出警报时,将其输出:

 someemail@example.com
   // why does i get this break line
 hello

I don't want a break line, what would be the cause? 我不要中断线,这是什么原因? I have been checking for the bug but unable to figure it out. 我一直在检查该错误,但无法弄清楚。

What's happening here is a "normal" line break as if you would hit Enter , not a <br> tag. 这里发生的是一个“常规”换行符,就像您按Enter一样 ,而不是<br>标记。

Make sure there are no hidden line breaks after the closing ?> . 确保在结束后没有隐藏的换行符?>

To avoid this happening, you can remove the ?> altogether. 为避免这种情况发生,您可以完全删除?> PHP doesn't require it at the end of the file. PHP在文件末尾不需要它。

change your php like this: 像这样更改您的php:

 <?php 
session_start();
include("configure.php");

$email =  $_POST['lemail'];
$ccode  =  $_POST['ccode'];
$email =  str_replace(array("\n", "\r"), '', $email );

 echo $email; 
?>

and just in case your jquery like this: 以防万一你的jQuery是这样的:

$('registration').click(function() {
       $.post('check_code.php',
        {lemail:$('input#pro_id').val(),ccode:$('input#ccode').val()},function(result){
        alert($.trim(result+"hello"););
    });     
});

check #ccode and #proid css values, and see if they are display: block; 检查#ccode#proid css值,看看它们是否display: block; . Change them to display: inline; 更改它们以display: inline;

edit: 编辑:

Also check to see if the texts are not in separate block elements. 还要检查文本是否不在单独的块元素中。 Like the <div> element that you mention in the comments. 就像您在注释中提到的<div>元素一样。 Change <div> in <span> for example. 例如,在<span>更改<div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM