Hongmu Notes
Home Language Notes Why does this code produce an extra '1' when executed? <?=require('./common/aside.php')?>
Language Notes PHP

Why does this code produce an extra '1' when executed? <?=require('./common/aside.php')?>

Why does this code produce an extra '1' when executed? <?=require('./common/aside.php')?>

Why does this code produce an extra value of 1?

<?=require('./common/aside.php')?>

In PHP,requireincludeThese statements are used to include content from other PHP files into the current file. They allow for the reuse of code across multiple files, thereby enhancing code reusability and maintainability.

In the aforementioned code,<?=require('./common/aside.php')?>The sentence is "will"../common/aside.phpThe content in the document has been imported into the current file and is now in use.<?=Output the content of this file.<?=expression?>Grammar is equivalent to<?php echo expression; ?>grammar.

If present in the included filesechoFor other `PRINT` statements, the statement that includes this file will return a result of 1. This output value of 1 occurs because the statement returns 1.

To solve this problem, you can./common/aside.phpEnsure that no `output` statement or any other statement generates output in the document. Alternatively, useincludereplacerequireStatement, becauseincludeThe statement does not interrupt program execution; instead, it returns a warning. As a result, no output of 1 will be generated.

How do I block this value of 1?

If you are using it<?=require('./common/aside.php')?>During sentence processing, it was discovered that a '1' appeared at the end of the page; this is becauserequireThe function returns a boolean value indicating whether the file was successfully included, while<?=expression?>Grammar will output this value to the page.

To block this value of 1, you can...<?=require('./common/aside.php')?>Change to<?php require('./common/aside.php'); ?>This way, no value will be rendered on the page, so the number '1' will not appear.

If you wish to use it<?=expression?>The grammar output contains the file content; it can be exported../common/aside.phpReplace any `output` statement with a `assignment` statement, then return a variable at the end, and then<?=require('./common/aside.php')?>Output this variable. This prevents the occurrence of the value 1. For example:

./common/aside.phpChinese:

<?php
$content = '这是侧边栏的内容';
return $content;
?>

In the main file:

<?=require('./common/aside.php')?>

The resulting output is:这是侧边栏的内容Instead of showing '1'.

微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

PHP ob function record

PHP ob function record Language Notes PHP

Usage of the following three functions ob_get_contents(); ob_end_clean(); ob_start(); You can use these functions to buffer local files and execute local script code. Use ob_start() to save the output code into the buffer, and the page will not be displayed; then use ob_get_contents to get the data in the buffer. o…
👁 141
PHP preg

PHP preg Language Notes PHP

The preg_match_all function is used to perform a global regular expression match. preg_match_all() Syntax int preg_match_all ( string $pattern , string $subject [, array &$matches [, int $flags = PREG…
👁 169
Detailed explanation of PHP ternary operator and if

Detailed explanation of PHP ternary operator and if Language Notes PHP

Ternary operator condition ? Result 1 : Result 2 Explanation: The position in front of the question mark is the condition for judgment. If the condition is met, the result is 1, and if it is not met, the result is 2. This article compares and explains the ternary operator and if...else... in detail. I hope it will be helpful to everyone. Today when I was revising my paper online, I encountered a statement that I couldn’t understand: $if_summary = $row['IF_SUMMARY']=…
👁 189
PHP cast type

PHP cast type Language Notes PHP PHP collection PHP and mysql

Get the data type 1. If you want to check the value and type of an expression, use var_dump(). 2. If you just want to get an easy-to-read type expression for debugging, use gettype(). 3. To check a certain type, do not use gettype(), but use the is_type() function. Converting Strings to Numbers When a string is evaluated as a number, the result is determined according to the following rules...
👁 232

Recommended reading

(Adaptive mobile version) PBootCMS template for electronics websites; Download source code for digital camera websites – 1029

(Adaptive mobile version) PBootCMS template for electronics websites; Download source code for digital camera websites – 1029 Practical Collection pbootcms Template

An electronic product and digital camera website template (PbootCMS), compatible with both PC and WAP devices. Featuring a modern, tech-oriented design ideal for showcasing electronic products, cameras, or brand images. It helps digital brands attract tech enthusiasts online and boost product sales. Template Preview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn | Related Articles...
👁 57
Responsive Data Security Website Template 0580

Responsive Data Security Website Template 0580 Practical Collection Yiyou template

This EyouCMS responsive template is ideal for the data and information security industry. Its modern, secure design effectively showcases data security products, information security services, solutions, and technical expertise. It helps cybersecurity companies present their brand online and attract corporate clients. Template Overview | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS...
👁 54
(Adaptive Mobile Version) Responsive High-Tech PbootCMS Website Template – Download HTML5 Technology & Energy Website Source Code – 0324

(Adaptive Mobile Version) Responsive High-Tech PbootCMS Website Template – Download HTML5 Technology & Energy Website Source Code – 0324 Practical Collection pbootcms Template

This adaptive, mobile-friendly responsive high-tech PbootCMS website template is built using HTML5 technology. Its cutting-edge design style is ideal for showcasing energy technologies, high-tech products, and innovative achievements, helping technology-driven enterprises establish themselves as industry leaders online. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s...
👁 74
(Adaptive mobile version) Chinese-English children's wear foreign trade website – PBootCMS template; Download children's wear website source code – 1030

(Adaptive mobile version) Chinese-English children's wear foreign trade website – PBootCMS template; Download children's wear website source code – 1030 Practical Collection pbootcms Template

A Chinese-English PbootCMS website template for children's wear export businesses, compatible with both PC and WAP devices. Its stylish and cute design is ideal for children's wear exporters to showcase their product ranges and export advantages. Multi-language support facilitates the global promotion of children's wear brands. Template Preview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn | Related Articles: Pbo...
👁 54
Eight Methods of the Spirit Turtle

Eight Methods of the Spirit Turtle Hobbies Memo notes

Generally used in emergencies. The stems and branches, the month number corresponds to the stems and branches, plus the hour. Five numbers, men take Zhaohai, women take Neiguan. List is missing - Zhaohai Neiguan - Gongsun Linqi - Waiguan Houxi - Shenmai Ziwu Liuzhu Men are on the left and women are on the right  
👁 1086
Website Development – Marketing Website Templates 0581

Website Development – Marketing Website Templates 0581 Practical Collection Yiyou template

An eYouCMS template designed for website development and marketing websites. Its modern, tech-driven design is ideal for showcasing website development projects, marketing services, technical solutions, and corporate strength. This template helps digital marketing agencies attract business clients seeking website development or promotional services online. Template Overview | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for eYouCMS | eYouCMS...
👁 49