Jump to content

[SOLVED] beginner problem with ECHO


deane

Recommended Posts

Hi guys, I'm new here, and I'm also new at php. I'm teaching myself really, and there are a lot of things that I don't understand yet. My current problem is the following code:

 

<html>

<head><title>Print 10 Times</title></head>

<body

<?php

$string = "Look, I'm red then I'm blue!";

 

// use FOR loop to print the value of $string 10 times

for($i = 1; $i <= 10; $i++)

echo "<h1>$string</h1>";

 

?>

 

</body>

</html>

 

The problem is the echo line (in bold). The first string printed is not the size of h1 while the rest are all in h1. However, if I change it like this echo "<h1><h1>$string</h1><h1>"; then all of them become h1. Why is this? Why do I need 2 <h1> tags? Thanks for your help on this fellas. I'll probably post some more when I hit roadblocks like this during my PHP self-teaching experience. BTW, I'm using WAMP on my PC.

Link to comment
https://forums.phpfreaks.com/topic/135449-solved-beginner-problem-with-echo/
Share on other sites

OMG lol, I lost sleep over this. Thanks for clearing that up. I guess being a programmer requires a keen eye  :D

 

It happens to everyone. Just as you get more advanced the stupider the answer is...seriously. It is always the small little stupid thing that makes a script go bad.

 

I've spent countless hours on a problem and the solution ended up being something that was soo simple I should have saw it first.

 

But yea, it still happens to me.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.