View Full Version : basics
Frog Brew
02-02-2007, 05:55 PM
Ok I am still getting though the basics here.
special characters you can use in strings: \n and \t. You
can use \n to start a new line in a string, as in the following statements:
So I put in
$string = “Hello \nWorld”;
echo $string;
But the output is still Hello World instead of
Hello
World
thetestingsite
02-02-2007, 05:58 PM
Try
$string = "Hello \r\nWorld";
echo $string;
Then it should display:
Hello
World
Frog Brew
02-02-2007, 06:04 PM
I just tried that and it did not work... :confused:
still displayed Hello World
This is because HTML ignores linebreaks.
If you look at the source, you will see:
Hello
Worldbut if you want to display a linebreak in HTML, you must use <br> (or, preferably, start a new block-level element; <br> is rarely appropriate).
Frog Brew
02-02-2007, 06:15 PM
That's what I had been doing prior to reading this, so now I am confused as to why would anyone use \n or \t anyways?
I am sure there is a good reason I just don't know it.
thetestingsite
02-02-2007, 06:16 PM
That's what I had been doing prior to reading this, so now I am confused as to why would anyone use \n or \t anyways?
I am sure there is a good reason I just don't know it.
I would think mostly for automated messages (emails) or inserting data to a text file, and stuff like that.
Added Later: I forgot about HTML ignoring line breaks. Thanks Twey for refreshing my memory on this.
That's what I had been doing prior to reading this, so now I am confused as to why would anyone use \n or \t anyways?
I am sure there is a good reason I just don't know it.Because PHP outputs to other formats than HTML :)
Plus it's a convention still common from C.
Frog Brew
02-02-2007, 06:25 PM
Ok thanks...am I dislodging memories from wake back when lol..;)
Frog Brew
02-02-2007, 07:18 PM
Also...is it possible that some things may not work because I reading a book on PHP 5 ? My version on the server is 4.4.4.
<?php
$string1 = "Hello";
$string2 = "World!";
$stringall = $string1.$string2;
echo "$stringall";
?>
Notice that no space appears between Hello and World!. That’s because no
spaces are included in the two strings that are joined. You can add a space
between the words by joining three strings together — the two variables and
a string that contains a single space — with the following statement rather
than the earlier statement:
$stringall = $string1._ _.$string2;
I am trying to get measly space between the 2 words and it's not working. I am going by the books intructions.
mburt
02-02-2007, 07:25 PM
You don't need quotes around the echo. Try this:
$string1 = "Hello";
$string2 = "World!";
$space = " ";
$stringall = $string1.$space.$string2;
echo $stringall;
If you want multiple spaces...
$string1 = "Hello";
$string2 = "World!";
$max = 3; // number of spaces
for ($i = 0;$i<$max;$i++) {$space.="$nbsp;"};
$stringall = $string1.$space.$string2;
echo "$stringall";
Frog Brew
02-02-2007, 07:41 PM
I assume   inserts a the space, but in the 2nd set of code you lost me with for ($i = 0;$i<$max;$i++)
May I say you guys are freaks, I mean this as a compliment and I am envious of your abilities.
LOL when I grow up I wanna be a freak too.
is the HTML code for a non-breaking space. These are used because normal spaces are treated specially (without text, they're ignored; if more than one space is in a row, all but one are ignored).
for ($i = 0;$i<$max;$i++)This is a for loop, common to most C-like languages (and some that aren't C-like at all). The syntax is:
for(initialiser; condition; incrementor)and the meaning is:Execute the initialiser Check that condition is true; if not, break from the loop Execute the following statement or block of code Execute the incrementor Repeat from 2Any of the three statements can be omitted, but the semicolons must still exist (for(;condition;) is equivalent to while(condition), and for(;;) is equivalent to while(true)).
mburt
02-02-2007, 07:59 PM
Thanks Twey for the explanation.
for( ; ; ) is equivalent to while(true)).
Don't try it though, it will never end causing the browser to freeze.
There's a timeout defined in php.ini that will kill any script that takes too long to run.
mburt
02-02-2007, 08:38 PM
I guess it's not in my server's settings. I made my browser "freeze" by using a never-ending loop (I set the condition (i < 15) to -15 by mistake).
Frog Brew
02-02-2007, 10:32 PM
I have no coding experience what so ever... so even though I really appreciate the explanation it seems may as well be in Chinese. (Which I can't read)
I am going to keep pushing forward though.
mburt
02-02-2007, 10:43 PM
I am going to keep pushing forward though.
Good attitude, alot of people just give up (I did for C++ Windows API, lol. Just getting back into it now). Hopefully you'll get where you want to be.
Frog Brew
02-02-2007, 11:05 PM
Well I just need to push through this, CSS style sheets, and MySql, (which is really kind of boring now because I am not applying it anywhere.) Once I start a site which has a purpose, it will be interesting to see. I know that I don't have a chance in hell though if I don't at least take the time to have a basic understanding.
I did for C++ Windows APII don't blame you.
mburt
02-03-2007, 12:03 AM
Actually, I'm starting to get the hang of it. Given, I also took three hours to read the tutorial, instead of cut/pasting code into CodeBlocks and letting her go :D
Frog Brew
02-03-2007, 12:19 AM
ummm anyone know of any good tuts for (video preferable) for PHP MySql and CSS? I have seen them online and I was actually willing to purchase, but that would be like me shopping for a good china pattern....clueless
A video PHP/MySQL tutorial? What would the point of that be? Have a look at w3schools.com for some usually-decent tutorials.
Frog Brew
02-03-2007, 01:09 AM
Not sure, just trying to find everything and anything I can...anyhow I checked out your link and it appears pretty indepth.
Thanks
mburt
02-03-2007, 02:44 AM
For PHP/MySql this is the one I used:
http://www.freewebmasterhelp.com/tutorials/phpmysql
Frog Brew
02-03-2007, 02:59 PM
You guys rock, and to think I found this site burried in some code.
/***********************************************
* Cool DHTML tooltip script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.