Welcome Guest!
Please login or register.

Main

User Info

Welcome, Guest. Please login or register.
September 04, 2010, 07:14:39 PM

Login with username, password and session length

Themes


Site Stats

Members
  • Total Members: 79
  • Latest: tamasir
Stats
  • Total Posts: 306
  • Total Topics: 64
  • Online Today: 7
  • Online Ever: 54
  • (May 24, 2010, 09:32:59 AM)
Users Online
Users: 0
Guests: 6
Total: 6

Author Topic: PHP Lesson -- echo  (Read 9562 times)

Offline IchBin™

  • Administrator
  • Full Member
  • *****
  • Posts: 145
PHP Lesson -- echo
« on: June 11, 2007, 07:22:48 PM »
The echo() construct:

echo() is also equal to print(). What echo does is that it outputs anything you put into it. For instance, you can put PHP and HTML in the echo statement and it will parse both the html string and the php code. There is a few things to remember when using an echo statement. Using single quotes or double quotes does not matter. However, if you use double quotes and then you use HTML that has some double quotes in it you'll get an error. If you do it this way you have to escape the extra double quotes. I'll give a couple of examples so that it will make these things clear.

Example #1:
echo('<p>This is an html paragraph</p>');
Outputs - This is an html paragraph
Notice the parenthesis (). They are not required. However, the use of a single quote or the double quote is required if your outputting HTML or text. Also, you MUST end an echo statement with a semi-colon. This tells php that your echo statement is finished.

Example #2:
echo'<div>Some html</div>'strtolower('TRANSFORM ME TO LOWER TEXT'), '<hr />';
Outputs - Some html transform me to lower text

Notice I have mixed html and PHP here. Anytime you mix php/html you have to escape to PHP. You do this by using ',
You also have to escape back to html if you use html after the php. You'll notice I also do that by reversing the order of the escape like this ,'
The strtolower (string to lower), transforms what ever string you put into it to all lower case.

Example #3:
echo"<table align=\"center\"></table>";
Notice how I escaped the extra double quotes in the HTML. This is the reason I prefer to use single quotes. You can do the same thing without escaping. :) But the same rules apply, if you have extra single quotes you'll have to escape them as well.

Example #4:
$mystring 'This is my string that I have assigned to the mystring variable';
echo 
$mystring;

Outputs - This is my string that I have assigned to the mystring variable
Here I have assigned the string to a variable and then echo'd the variable. Whenever you're echoing ONLY php the quotes aren't required, but of course the semi-colon is. :)

I think I'll add more to this if any questions arise, or if I have forgotten something. :) Feel free to post your thoughts if you have any.

« Last Edit: June 11, 2007, 07:30:12 PM by IchBin™ »
Signatures Go here!!

Offline JW01

  • Jr. Member
  • **
  • Posts: 11
Re: PHP Lesson -- echo
« Reply #1 on: June 22, 2007, 06:41:53 AM »
Thanks for the lesson!!  I have been running various php sites for a few years and am still a noob at a lot of the coding.   What will the next lesson cover?

Offline IchBin™

  • Administrator
  • Full Member
  • *****
  • Posts: 145
Re: PHP Lesson -- echo
« Reply #2 on: June 22, 2007, 12:47:59 PM »
I haven't decided yet. Still being a novice in my own mind, I will just post things as I see fit. If you have any suggestions feel free to say. :)
Signatures Go here!!

Offline rebelrose

  • Jr. Member
  • **
  • Posts: 20
Re: PHP Lesson -- echo
« Reply #3 on: October 12, 2007, 04:49:35 PM »
I haven't decided yet. Still being a novice in my own mind, I will just post things as I see fit. If you have any suggestions feel free to say. :)

Surely your no novice in any sense of the word, if you look it up in the dic. you will see my picture. 

Offline william777

  • Newbie
  • *
  • Posts: 3
    • Lee Young Ae Fans Club
Re: PHP Lesson -- echo
« Reply #4 on: December 25, 2007, 06:04:32 PM »
Thanks IchBin for the lessons. i AM a PHP novice.
Bless my Lord, O my soul - Psalm 103

healthboss.com

  • Guest
Re: PHP Lesson -- echo
« Reply #5 on: February 13, 2008, 11:37:35 AM »
great day to you all

Offline IchBin™

  • Administrator
  • Full Member
  • *****
  • Posts: 145
Re: PHP Lesson -- echo
« Reply #6 on: February 15, 2008, 01:37:35 PM »
And a great day to you. I hope the tutorial helped. :)
Signatures Go here!!

Offline Smoky

  • Jr. Member
  • **
  • Posts: 21
    • PixelbyPaint
Re: PHP Lesson -- echo
« Reply #7 on: June 06, 2008, 11:19:14 PM »
thanks ICH, think seeing examples does help.. was going to try and write something funny, lol but the

Code: [Select]

echo'<p>brain isnt working at this time of night so heading to bed</p>';


will work for me now  :kp: :D


Offline IchBin™

  • Administrator
  • Full Member
  • *****
  • Posts: 145
Re: PHP Lesson -- echo
« Reply #8 on: June 07, 2008, 12:19:24 PM »
haha, yep it looks like you understand echo () :)
Signatures Go here!!

Offline Smoky

  • Jr. Member
  • **
  • Posts: 21
    • PixelbyPaint
Re: PHP Lesson -- echo
« Reply #9 on: June 07, 2008, 10:08:30 PM »
more ICH!!! please..  :P :kp:

i think with what i am doing with dreamweaver, and yes i know what you think on it, but it actually helped me today in debugging validation on the html.. but i am learning slowly but surely..  :azn: