english

learn php

learn css

learn html

learn javascript

learn php

3. types & strings

assignments
2 minutes / 340 words

three / assignments

assignment 3.1

create two variables, one with the title and the other with the text of the first paragraph of any news article.

change the title to be all-caps.

replace every period with an exclamation point.

replace every "and" with &.

replace every question mark with five question marks.

replace every number with *.

make sure there are no extra spaces before or after either variable.

write both variables to the screen.

assignment 3.2

this is not an assignment where you're creating something, more one to test your understanding of types. there's a long list of built-in constants in php. the exact number depends on your specific installation. on my local machine, there are 3025, for example.

to see if you can quickly identify the common types used, create a php program whose contents are...

print_r(get_defined_constants(true));

it will give you a list of the constants in your php installation. if you set constants, they will also show up in that list. in this case, you're not setting any so you'll just see the built-ins.

go through the list and write what you think the type is for each item. no, you don't need to do thousands of them. pick some. you're not doing this as punishment, just a way to test what you've learned about types.

then check your answers. run the same program but change print_r to var_dump. you'll get the same output but it will tell you the type (and often the size) of each constant.

if you got them all right, great. if you didn't, pick some more on the original list to try and check again to see if you did better.

don't forget that, when things can be many different types, they're usually the simplest one. for example, 20 could be a float or an int or even a string. but it's going to be an int unless there's a very good reason for it not to be. 20.1, though, will default to being a float because it can't be an int.

learn php

learn css

learn html

learn javascript

powered by akelei. an avi sato project.