Hi,
How do I echo echo's? I need it to include pages with these commands.
Ex.
PHP Code:echo "
echo "Blah blah ";
";
Printable View
Hi,
How do I echo echo's? I need it to include pages with these commands.
Ex.
PHP Code:echo "
echo "Blah blah ";
";
I am completely confused :confused: :)
What is the problem with your code?
Is it
1) The quotes inside quotes? If so, use the backslash to escape the inside quotes (as in $var = "... \" ... "), or better yet, use single quotes for the enclosing string.
or
2) Getting data from a file and echoing it?
Is what your saying?
That you need to "include" "files" with echo's in them?
include('pagename.php');
Or is it something like this
You know... what pengate said.PHP Code:<?php
echo"
<H1>This is an echo inside an echo - double quotes x2</H1>
echo\"Wassup\";
";
//Also this works
echo'
<H1>This is an echo inside an echo - double quotes in single quotes</H1>
echo"Wassup";
';
//Also this works
echo"
<H1>This is an echo inside an echo - single quotes in double quotes</H1>
echo'Wassup';
";
//Ect
?>
Well, the code is
This variable, $tekst, is echoed from another page that includes (include("blahblah.php")).PHP Code:$tekst = "
Velkommen til din logbog! Her kan du føre regnskab med din motion. Hvis du løber tør for aktivitets-idéer,
så kan du altid tjekke Idé-maskinen, der automatisk foreslår en tilfældig aktivitet.
<br>
Varigheden angives i timer; men har du f.eks. motioneret i 1½ time, så skal du skrive \"1.5\" - med punktum og ikke komma.
<p><center><b>Jeg har indtil videre lavet dette:</b><br>
<table width='100%' border='1' cellspacing='0' cellpadding='0'>
<br>
<tr>
<td align='center' width='33%'><b>Dato</b></td>
<td align='center' width='33%'><b>Aktivitet</b></td>
<td align='center' width='33%'><b>Varighed</b></td>
</tr>';
<?php
$n=0;
$brugernavn = ". $_SESSION['s_username'].";
$query = mysql_query('SELECT aktivitet,dato,varighed FROM $brugernavn') or die(mysql_error());
while ($newArray = mysql_fetch_array($query)) {
$aktivitet = ".$newArray['aktivitet'].";
$dato = ".$newArray['dato'].";
$varighed = ".$newArray['varighed'].";
$n=$n+$varighed;
if ($aktivitet==NULL) {
echo '<center><br>Intet endnu</center>';
}else{
echo "
<tr>
<td align='center' width='33%'>$dato</td>
<td align='center' width='33%'>$aktivitet</td>
<td align='center' width='33%'>$varighed time(r)</td>
</tr>
";
}
}
echo "
</table>
<br><b><center>Ialt: $n time(r)</b></center><br>
<br><a href='aendr.php'>Ændr aktiviteter</a>
<br><br>
";
echo "
<table width='100%' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td align='center' width='33%'>Dato</td>
<td align='center' width='33%'>Aktivitet</td>
<td align='center' width='33%'>Varighed (timer)</td>
</tr>
<tr>
<td colspan='3' align='center'><form name='form2' method='post' action='addlog.php'>
<input name='dato' type='text' size='25'>
<input name='aktivitet' type='text' size='25'>
<input name='varighed' type='text' size='25'>
<p align='right'>
<input type='submit' name='Submit2' value='Tilføj'></p>
</form></td>
</tr>
</table>
<b>Idé-maskinen:</b><br>
END;
$ide = mysql_query('SELECT * FROM idemaskine') or die(mysql_error());
$rows = mysql_num_rows($ide);
$id = rand(1,$rows);
$data = mysql_query(\"SELECT aktivitet FROM idemaskine WHERE id = '$id'\") or die(mysql_error());
$row = mysql_fetch_array($data);
$aktivitet = ".$row['aktivitet'].";
echo<<<END
<table width='100%' border='1' cellspacing='0' cellpadding='0'>
<tr>
<td height='30' bgcolor='#CCCCCC' align='center'>$aktivitet</td>
</tr>
</table>
</center>
<a href='logout.php'>Log ud</a>
";
}
";
I have a question? Where on earth did you learn to write PHP like that? I wouldl ike to meet the person who taught you .... and kill him. :p
It's self-taught and I don't usually write it this way. I kinda tried to work it around to make it work :P
Fact is, no one is going to want to help you if you don't put the effort into writing clean readable code. Incase you didn't already know:
- Indent your code. Whenever you use braces, {} tab out:
This is good:
This is bad:PHP Code:while(true) {
if($condition) {
echo('blah');
}
}
PHP Code:while(true) {if($condition) {
echo('blah');
}
}
- I have no idea what is meant by this:
But you can embed variables in side double quoted strings as follows:PHP Code:$brugernavn = ". $_SESSION['s_username'].";
PHP Code:$string = "Hello i am an embeded {$var} and so is {$_SESSON['blah']}";
- PHP is not Perl. It is an HTML embedded scripting language. DO NOT echo huge chunks of HTML at a time:
This is bad:
This is good:PHP Code:echo "
<tr>
<td align='center' width='33%'>$dato</td>
<td align='center' width='33%'>$aktivitet</td>
<td align='center' width='33%'>$varighed time(r)</td>
</tr>
";
PHP Code:?>
<tr>
<td align="center" width="33%"><?php echo($dato) ?></td>
<td align="center" width="33%"><?php echo($aktivitet) ?></td>
<td align="center" width="33%"><?php echo($varighed) ?></td>
</tr>
- Single quotes should never be used for attribute vlaues in HTML.
Use those tips above to edit the code you have and make it look respectable and get into the habbit of us coding properly, otherwise you will be the one who suffers.
Ok, thanks. But that doesn't really answer my question :S
Hmm, I'll just try something else...something less stupid :D
I deliberatly didn't answer your question and won't unless you make your code look more respectable.Quote:
Originally Posted by sveegaard
Please be gentle to a newbie Ö
VisualAd is not meaning to be horrible, but it is hard for other people to read code which is badly formatted. It can take a long time to understand badly formatted code to see a simple problem.Quote:
Originally Posted by sveegaard
I understand that you are new to PHP - but If you have a go and try (I've given you are few tips) and post what you come up with. I'll be happy to help. I am not happy to help those who do not put the effort in though.
Hes right, i was bugging visualad on msn earlier, as he was refusing to answer my question i learnt it myself.
Now code right!
ILMV