Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
It's also a language that grew from a temporary need. But yeah, PHP sucks.
And no, that's just PHP. -
OH MY GOD, NOW HE'S CREATING A PHP FILE footer.php WITH ONLY 3 HTML TAGS AND NOTHING ELSE, AND THAT TOO:
</div>
</body>
</html>
IN THE NAME OF MODULARIZATION!!!
i am gonna puke🤮 🤮 🤮 -
PSR-1 disallows this (2.3). It works because PHP is a templating language at its roots, but it's discouraged. The only practical reason to learn about this is to not be surprised later when you do this by accident.
-
hjk10156965y@ScriptCoded no that is rape... Just that you don't like how she dresses doesn't make it right!
FFS at least use alternative syntax not that it's needed here; one can obviously go without the tags and just print the damn thing. -
Okay, if I'm not supposed to do this then how exactly do I create templates in PHP? (Ignoring of course the option to unnecessarily print the whole thing which leads to the same result but with more commands and no chance for syntax highlighting)
-
@Lor-inc You use a proper templating engine like Twig or Blade, which will enforce view-logic separation.
-
hjk10156965y@Lor-inc it is best to use a true template parser like twig but if that is overkill it can be done like this
<?php
//Includes and boilerplate here
$result = $db->query('select stuff');
?>
<!DOCTYPE html>
<html>
<body>
<ul>
<?php while ($row = $result->fetch(PDO::FETCH_OBJ)):?>
<li>
<label>name:</label>
<span><?php echo $row->name;?></span>
</li>
<?php endwhile; ?>
</ul>
</body>
</html>
Excuse the poor formatting. It's hard on a phone. Usually it is used when there is a lot of html and very little PHP inside the flow control statements -
@hjk101 If there's more than a little PHP in a template then syntax isn't your greatest problem.
Related Rants
Instructor: "and now here we can write this while loop in ph- oh wait. Let me just show you a cool trick. I am gonna close this php tag with ?> , open an html tag , then again open this php tag , add this line, close it, then again close html tag, then again open php, and then close it. pretty crazy huh? You see, now we can have our cool bootstrap displaying this output beautifully"
Me : FUCK YOU MAN :|
for reference, this was the final output :
============================
<?php
while($row = mysqli_fetch_assoc($result_successful)){
?>
<pre> <?php print_r($row); ?> </pre>
<?php
}
============================
I am a newbie in web dev who comes from a very nice java/kotlin world. is this a common site in web dev, mixing of all the html/php/some 1000 more laguages and frameworks to make 1 working product? coz it sucks.
rant
php tutorial
udemy