Reputation: 57
My thing is when I echo my php code it doesnt echo the code it echo's numbers in return I am trying to add a PHP code to my website so every week the text on the website would update from a stored file like quotes.txt. Is there something wrong with my php any suggestions? Here is a screenshot of what happens https://gyazo.com/fba5fc414228b1ab2a79bb877642477a
My Code :
<div class="wrapper">
<div class="teachings">
<h1 id="teach">Teaching's</h1>
<hr>
<?php
$text = file_get_contents("quotes.txt");
$text = trim($text); //This removes blank lines so that your
//explode doesn't get any empty values at the start or the end.
$array = explode(PHP_EOL, $text);
$lineNumber = date('s');
echo "<p>$lineNumber</p>";
?>
<h1>Weekly Teachings :</h1>
<br>
</div>
</div>
Upvotes: 1
Views: 91
Reputation: 94662
You are echoing the currect second value from a date('s')
function call
I assume you want to echo the number of lines in the array
$array = explode(PHP_EOL, $text);
$lineNumber = count($array);
echo "<p>$lineNumber</p>";
But if you intended something else, add a comment I I will attempt to change this answer accordingly
RE: Your comment below, then you want to do
echo "<p>{$array[0]}</p>";
Upvotes: 1
Reputation: 427
What you want to do is
echo $array[$lineNumber];
That will echo the quote whose line number is the week number.
Upvotes: 0