My question is related to php include prints 1. In https://github.com/jaimemontoya/jaimemontoya.com/blob/dev/page.php I’m using this:
public function Display() { echo "<!DOCTYPE html>nt<head>n"; $this -> DisplayTitle(); $this -> DisplayFavicon(); $this -> DisplayMetaKeywords(); $this -> DisplayMetaDescription(); $this -> DisplayMetaViewport(); $this -> DisplayStyles(); echo "t</head>nt<body>n"; $this -> DisplayHeader(); echo "tt<div class="container">n"; echo $this->content; echo "tt</div>n"; $this -> DisplayFooter(); echo "t</body>n</html>n"; }
The problem happens in echo $this->content;
. In https://github.com/jaimemontoya/jaimemontoya.com/blob/dev/index.php I’m using this:
<?php require("page.php"); $index = new Page(); $index->content .= require("scala-programming-projects/scala-programming-projects-book-info.php"); require("success-habits-dummies-zeller/success-habits-dummies-zeller-book-info.php"); ..... ..... ..... $index->Display(); ?>
The problem is the ‘1’ that is printed because the include()
method, after successfully including the desired file, returns a TRUE
value that when echo’ed out is ‘1’.
Do you have specific suggestions to refactor my code to get rid of that ‘1’ or maybe php.ini
or some configuration can help in this case? Thank you.
Advertisement
Answer
I see that your scala-programming-projects/scala-programming-projects-book-info.php
already concat the string. just remove concatenation on index.php
<?php require("page.php"); $index = new Page(); require("scala-programming-projects/scala-programming-projects-book-info.php"); require("success-habits-dummies-zeller/success-habits-dummies-zeller-book-info.php"); ..... ..... ..... $index->Display(); ?>