I would like to replace several text in a PHP file before I include it in my index.php
For example. The file that I'm about to include in my index.php is a template file called "main.php" and it contains code something like below:
<html>
<head>
<script src="js/jquery.min.js"></script>
<script src="js/jquery-migrate.min.js"></script>
</head>
<body>
Hi, [your_name]. Welcome to [company_name]. Enjoy your stay here!
</body>
</html>
and on my index.php I will have a bunch of queries to get data from database and put it into main.php file. Example below:
<?php
$sql_stmt = "select name, company FROM comp_info WHERE deleted='0' AND status='2'";
$sql = mysqli_query($conn, $sql_stmt) or die(mysqli_error($conn));
$row = mysqli_fetch_assoc($sql);
include_once("main.php");
?>
I tried to use this method below, but I dont know how to use it in this case:
str_replace("[your_name]", $row['name'], main.php);
str_replace("[company_name]", $row['company'], main.php);
So far, what I've searched from the internet is this : Replacing {{string}} within php file But it doesn't works for this case.