current position:Home>PHP makes a web page, adding code to the body block in HTML causes the page to be garbled, and cannot modify header information - headers already sent is displayed

PHP makes a web page, adding code to the body block in HTML causes the page to be garbled, and cannot modify header information - headers already sent is displayed

2022-02-02 19:47:33 CSDN Q & A

The phenomenon and background of the problem

use php Write a simple web page value transfer arithmetic unit , There is no problem after the preliminary construction , But modify the front end later html When the code changes its appearance, the page is garbled , Show Warning: Cannot modify header information - headers already sent by (output started at Z:\Xampp\htdocs\401.php:1) in Z:\Xampp\htdocs\401.php on line 129

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<title>r2code</title><link href="web.css" rel="stylesheet" type="text/css" /><style> .table { margin: 20px auto; } td { padding: 0 10px; } tr { height: 25px; }</style>
mouse
mouse
Total number of nodes Total number of fixed nodes Total number of members
  <table class="table">    <tr>      <td> Total load </td>      <td><input type="text" name="loadNum" /></td>      <td> Total number of sections </td>      <td><input type="text" name="secNum" /></td>    </tr>    <tr>      <td> Node coordinates X</td>      <td><input type="text" name="xArray" /></td>      <td> Node coordinates Y</td>      <td><input type="text" name="yArray" /></td>    </tr>    <tr>      <td> Left node of member </td>      <td><input type="text" name="leftNode" /></td>      <td> Right node of member </td>      <td><input type="text" name="rightNode" /></td>    </tr>    <tr>      <td> Member EA</td>      <td><input type="text" name="EA" /></td>      <td> Member EJ</td>      <td><input type="text" name="EJ" /></td>    </tr>  </table>  <table class="table">    <tr>      <td> The member number where the load is located </td>      <td><input type="text" name="loadBarNum" /></td>      <td> Load type </td>      <td><input type="text" name="loadSort" /></td>      <td> Load size </td>      <td><input type="text" name="loadMag" /></td>    </tr>    <tr>      <td> Distance from load to left end </td>      <td><input type="text" name="loadLeftLength" /></td>      <td> The member number where the section is located </td>      <td><input type="text" name="secBarNum" /></td>      <td> The distance from the section to the left end </td>      <td><input type="text" name="secLeftLength" /></td>    </tr>  </table>  <div align="center">    <p>  optional : </p>    <input type="checkbox" name="box[]" value="weight" /> Whether to consider self weight     <input type="checkbox" name="box[]" value="shear" /> Whether shear deformation is considered     <input type="checkbox" name="box[]" value="displacement" /> Whether there is node displacement   </div>  <table class="table">    <tr>      <td>x Specify the displacement node number in the direction </td>      <td><input type="text" name="Xnode" /></td>      <td>y Specify the displacement node number in the direction </td>      <td><input type="text" name="Ynode" /></td>      <td> Specify the displacement node number of the corner </td>      <td><input type="text" name="Znode" /></td>    </tr>    <tr>      <td>x Direction specifies the displacement </td>      <td><input type="text" name="Xspecifydisplacement" /></td>      <td>y Direction specifies the displacement </td>      <td><input type="text" name="Yspecifydisplacement" /></td>      <td> Specify the displacement of the corner </td>      <td><input type="text" name="Zspecifydisplacement" /></td>    </tr>    <tr>      <td>x Direction refers to the number of positioning shifts </td>      <td><input type="text" name="Xnum" /></td>      <td>y Direction refers to the number of positioning shifts </td>      <td><input type="text" name="Ynum" /></td>      <td> Angle refers to the number of positioning shifts </td>      <td><input type="text" name="Znum" /></td>    </tr>  </table>  <p>  </p>  <div align="center">    <input name="Submit" type="submit" value=" Calculation " />  </div></form><p>&nbsp;</p>
Operation results and error reporting contents

img

img


This is the result of garbled code

img


This is not in body The normal result of adding code at

My solution ideas and tried methods

The modified encoding format is not utf-8, No solution

What I want to achieve

Can add code on the basis of the existing appearance to modify the appearance without garbled errors




Refer to the answer 1:

header("content-type: text/html; charset=utf-8");
This sentence should be placed on the top line , There must be no space in front of it, line feed or other output




Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202021947296049.html

Random recommended