Page 1 of 1
specific code help
Posted: Mon Mar 22, 2004 9:19 pm
by bawla
i went to php.net and i was reading the manul which is very very very very long

and i read some things that i couldn't understand very well
below are the things i dont understand, if you could please explain it clrearly and as simple as posibile with a example if you could
----------------------------------------------------------------------------
strpos()
strlen()
foo - i've seen it in a few examples but i dont know why its being used
boolean - i know it has to do with something being FALSE or TRUE
array - totally dont get this one
object
session
function - can you set your own function or wut????
. - when sometime in a code they have $a = 3 and $b .=$a
----------------------------------------------------------------------------
thats all that i have for now

Posted: Mon Mar 22, 2004 9:29 pm
by markl999
Here's a quick, simple explanation of some of them. Whilst some arn't technically correct they give the general idea (i hope)
Code: Select all
<?php
//strpos (string position) example
//the below echo's 1 as the e is in position 1 (the h is 0)
echo strpos('hello', 'e');
//strlen (string length) example
//the below echo's 5, as hello has 5 characters in it
echo strlen('hello');
//foo
//See http://catb.org/~esr/jargon/html/F/foo.html
//boolean
//either true or false
//see http://php.net/manual/en/language.types.boolean.php
//array
//an array is just a 'collection' of values
$array = array('john','paul','george','ringo');
echo $array[3]; //will echo ringo
echo $array[0]; //will echo john
//object
//not going to go there ......
//session
//think i'll avoid this too for now
//function
//here's how to define and call/run your own function
function testing($name){
//$name is a variable and we can pass whatever value we like into it
echo 'Hello '.$name;
}
testing('fred'); //this will display Hello fred
testing('woooot'); //this will display Hello woooot
//. (concatenate)
//the . basically means append .. or add onto the end of
$a = 'hello ';
$a .= 'fred'; //this 'adds' fred onto the end of $a (which is hello)
echo $a; //echo's hello fred
?>
Posted: Mon Mar 22, 2004 9:33 pm
by andre_c
You can probably benefit a lot from a tutorial. Have you tried this one: php.net/tut. I also recommend the tutorials at phpfreak.com. Sorry I don't have time to give examples but I know you'll get it after going through a simple tutorials. Maybe someone else will have the time to write som sample scripts?
Edited: I guess somebody did
I agree with mark that you probably should learn some more before going into sessions and objects.
arrays are cool
Posted: Mon Mar 22, 2004 9:34 pm
by tim
i suppose i can tackle a few of those before I go to bed
Yes you can make your own function.
strlen will just count how many items make up a string, ie:
Code: Select all
<?php
$var = "ilovephp";
$count = strlen($var);
echo $count;
// this will display 8, i l o v e p h p (count em, 8 letters)
?>
An array in generic terms is basically a variable that can/does have multiple values 0 is actually 1 in a array, ie:
Code: Select all
$string = array('1', '2', '3', '4');
echo $string[0];
// this will echo 1.
Foo[bar] is usually just text they choose to show examples, which alot of the functions u asked for show examples of how they work on php.net.
http://php.net/manual/en/language.types.boolean.php, explained good there.
thats all i'm going to hit, bed time for me.
Posted: Mon Mar 22, 2004 9:38 pm
by bawla
whoa, this is very good information, thank you all, i understand most of those now since it was laid out simply (simple things for simple minds, lol) i love this place
Posted: Mon Mar 22, 2004 9:41 pm
by andre_c
... also the . means concatenate so:
Code: Select all
$sentence1 = 'The fox jumped ';
$sentence2 = 'over ';
$sentence3 = 'the fence';
$complete = $sentence1 . $sentence2 . $sentence3;
echo $complete; //outputs: The fox jumped over the fence
// or you can just
echo $sentence1 . $sentence2 . $sentence3;
I guess i did have a little time
Posted: Mon Mar 22, 2004 9:50 pm
by bawla
wut if there are 2 [dots]'s
for example
Posted: Mon Mar 22, 2004 9:52 pm
by markl999
Same thing.
Code: Select all
$one = 'one';
$two = 'two';
$three = 'three';
echo $one.' '.$three.' '.$two; //outputs one three two
Above there are 5 things being 'concatenated' together, 3 variables plus 2 spaces.
Posted: Mon Mar 22, 2004 9:53 pm
by andre_c
add whatever is next
Posted: Mon Mar 22, 2004 9:55 pm
by bawla
Code: Select all
if(mysql_num_rows($result)){
$row = mysql_fetch_assoc($result);
echo 'Username: '.$row['username']."<br>\n";
theres nothing to add
Posted: Mon Mar 22, 2004 9:58 pm
by markl999
echo 'Username: '.$row['username']."<br>\n";
There you are 'adding' (adding in the appending sense, not the mathematical sense) 3 things together, some text, a variable and a '<br>'
Posted: Mon Mar 22, 2004 10:47 pm
by bawla
o alright, i get it, thanks