KansukeKojima
Nov 14 2007, 11:13 PM
PHP Echo Description The echo() command has one purpose, displaying whatever you put in between the brackets. Learn to use it to your advantage. Try It Out CODE <?php echo ""; ?>
There is your echo command. For now, it does nothing. It has no value to display. CODE <?php echo "This is my text."; ?> Outcome This is my text. Now this echo command has a value to display. Whatever you replace "This is my text." with will be displayed. Alright, lets move onto the next step. This time, we will include a variable in the echo command. CODE <?php $var = "This is a variable"; echo "$var. Congratualations, you just parsed a variable in an echo!"; ?> Outcome This is a variable. Congratualations, you just parsed a variable in an echo! Got it? The variable ($var) had a value, and when you placed $var in the echo command, it was displayed. Sounds like a different language, right? Its ok if you don't understand yet, with some practice you will eventually understand it. These are the basics of the echo() comand. Not much to it if you are a beginner, but as you progress, there is much more.
Reply
hippiman
Nov 15 2007, 02:42 AM
This is something that could help if you actually have more HTML on your page than PHP. The echo tag is pretty much exactly like typing in HTML outside of the php tags, so you can also just end the php, and start it and end it whenever you have variables again or something. CODE <?php $var = "Someone's Name"; ?> Some HTML that you want to do. Some more HTML that has <?php $var; ?>. That should display: CODE Some HTML that you want to do. Some more HTML that has Someone's Name. You might have to put <?php echo $var; ?> instead of <?php $var ?> But I'm not really sure. Just try it, and it should work. At leas one of them will. That would only be better if you have a bunch of HTML and only a little PHP code. You could also use that to copy HTML over and over again: CODE <?php for($i=0;$i<100;$i++) { ?> some HTML that you want to loop 100 times. <?php } ?> I think I've tried that before, and it worked. If I have any errors in that, feel free to correct me. I hope this helps!
Reply
suberatu
Nov 15 2007, 04:34 AM
I don't have any experience with php, but at least now I know how to output basic text (or variable text) to the screen. Thanks for the brief, but useful tut.
Reply
Saint_Michael
Nov 15 2007, 04:54 AM
Echo's are a great way to start off in learning php as it will help you understand how variables will work and when you start working with php includes when designing full scripts.
Reply
pop
Nov 15 2007, 11:54 AM
instead of echo sometimes it's usefull to use printf, like in C language. $value1 = "my test var"; $value2 = 200; printf ("%s has size of %d", $value1, $value2);
Reply
Tetraca
Nov 15 2007, 12:23 PM
The different types of quotes are equally important as well. Without them you'd have to sit there trying to print values in ASCII character codes you wanted to see. CODE echo "These basic quotation marks allow you to use the apostrophe and are useful for basic text."; echo 'These single quotes allow you to use standard quotemarks and are useful for dispensing HTML code'; echo `These grave accents allow you to put both single and double quotes`; They work for variables in this language as well. I end up using them a lot within my code. I don't often end up using the printf function, though. It reminds me of C and why I dislike it.
Reply
KansukeKojima
Nov 15 2007, 03:29 PM
One thing that I have recently learned and that I will be using for my website once I remake it (I've shut it down for now) is using echo to help create a sweet layout... bassically program all your variables at the top of the page, code them into another variable called template and then echo the template variable... I estimate that it will work quite nice because you can make large changes easily and quickly... and I think this method would work quite well. EDITED IN AFTER POST:It would look like this CODE <?php //-------------------------- //Content itself //-------------------------- $content[1] = <<< html blablablabla html; $content[2] = <<< html blablabla again html; //------------------------ //layout design with content in it //------------------------ $template = <<< html <table width=500> <td> $content[1]</td> <td> $content[2]</td> html; //-------------------- //show the page //-------------------- echo "$template"; ?>
Reply
OneMinute
Nov 16 2007, 02:05 AM
In PHP, we can also use Print? (Yes, indeed) But it's just a matter of preferences however. The print is also setted to display the output. Please correct me if i am wrong; i just started learning php.
Reply
coolcat50
Nov 16 2007, 09:09 PM
You should have also provided a few other tricks with echo. Such as random numbers or something like that. Look at this code. CODE <?php $var1="Hello people!"; $var2=str_replace("people","world",$var1); echo $var1." and ".$var2; ?> The above code should display. CODE Hello people! and Hello world! So echo can actually be used for several purposes.
Reply
KansukeKojima
Nov 17 2007, 01:47 AM
More on the note of using the magical skill of parseing variables in echos, here is dandy fine random title/subtitle/whatever code. CODE <?php $text[1] = "Hey ma whats for dinner"; $text[2] = "Go up yo nose and picka winna!"; $text[3] = "EWWWWWW......";
$randomize = rand[1, 3]; echo "$text[$randomize]"; ?>
Get it, you have three different options, you create a variable called randomize and use the rand function to select from the previous array. The you echo the text variable and the randomize variable as shown above.
Reply
Similar Topics
Keywords : php, echo, learn, echo, includes, basic, echo, variable, p
- Php Variable Basics
Where would PHP programmers be without the variable? Learn all about t (9)
Templating System Using Php Includes
Building a Dynamic site using Includes and flat-files. (13) Php based Templating System http://jlhaslip.trap17.com/template/index.php The Source Code
for the scripts are included (literally) on the different pages on the Demo, including the Contact /
Email script. The only page not there yet is the Message Script. Maybe tonight I will upload that.
This one uses a little bit of query-string checking to confirm that the contents of the page are
actually available (file_exists())and an allowed page content before serving it up. The
'allowed page content' is done by checking against a flat-file containing an array....
Looking for php, echo, learn, echo, includes, basic, echo, variable, p
|
*RANDOM STUFF*
*SIMILAR VIDEOS*
Searching Video's for php, echo, learn, echo, includes, basic, echo, variable, p
*MORE FROM TRAP17.COM*
|
advertisement
|
|