PHP 2MDST 3559:  DataestheticsProf. Alvarado02/17/2011
BusinessVPN?
ReviewPHPVariables, Data Types, FunctionsSee Chapters 2 through 5 of Programming PHPTextEarlier we saw the text handled as a tree (CSS, jQuery)Tuesday we treated the text as an array, a simple linear sequence,
OverviewToday we will go back over the basics of PHP To provide a slightly different angle on the subjectTo help clarify some concepts for those new to programmingTo help clarify the “PHP way” for those with experienceThen we will cover two new topicsRegular ExpressionsCreating your own functions
PHP as a languagePHP is a programming langague (of course), but it has analogies to natural language as wellThere are parallels to the basic structures of human languagesWhich makes sense: Programming languages are designed to mediate between human and machine language
What are some elements of natural language?
Some Elements of Natural LanguageWordsMeaningsSentencesSomething is said of something elseParts of speech: nouns, verbs, prepositionsHeart of language as language, beyond mere signsParagraphs
PHP has all of these things
Values are MeaningsValues are pieces of dataLanguages are all about doing things with dataData comes in typesTypes include strings and numbersAlso Boolean values (true/false)Values are expressed literally and signified like so:“Hello, World!”5trueThese are the meanings of the language
Variables are NounsVariables are words that can have meaning$POTUS = “Obama”;The President of the U.S. is Obama.Like the difference between person and office They are like nouns that refer to things Things being values ...They are always prefixed by $ and are case sensitive
(Arrays)Arrays are admittedly weirdBut they can be thought of as words that stand for collections, e.g.The Pittsburgh SteelersThe UVA student bodyThese phrases imply a structureAlbeit much more complicated than arraysBut not much: consider rosters ...
Functions are VerbsFunctions are like verbs$food = food_shop($me,$money,$humger_level)Like verbs, they may require arguments and imply a resultVerbs are action wordsConsider transitive versus intransitiveThey are not prefixed by $They are not case sensitiveThey are followed by parentheses
FunctionsVerbs have implicit arguments and effectsSubjects, objects, indirect objects, are like argumentsIntransitive verbs are like functions that don’t take an argumentOr, it is implicit (the subject)Functions like verbs imply actions that produce effectsPerson A: He ran for office.Person B: And ... ?
ExpressionsExpressions are like phrases that combine nouns and verbs5(5 + 10) / 36“Tina” . “ is my cat”;file($url)$fooAll expressions result in a value50.4166666 ...Tina is my cat[the array of the file][whatever $foo was last set to]
StatementsStatements are like sentences.   They combine one or more expressions.$my_cat = “Tina”;$x = 2+2;They say something about somethingMy Cat is Tina.$foois 2+2 (is 5)The verb “to be” is an assignment operator ...They are always punctuated by a semi-colon
OperatorsExpressions and statements are built out of words by combining them with grammatical words, such as prepositions and conjunctionsIam in the house.I own a catanda dog.Operators are like the grammatical wordsThey don’t have meanings, they have functionsThey don’t reference values (i.e. data), they do things with values
OperatorsArithmeticAddition, subtraction, division, multiplication, etc.StringConcatenationAssignmentX is YLogicalIs X Y?Is X related to Y in some  specified way?
StructuresStructures, or control structures, are like stories or narrative patternsBuilt-in functions control conditions and iterationRepetition and branching
Conditionsif / elseif/ elseif ($x == ‘foo’) {	// do something} elseif ($x == ‘bar’) {	// do something else } else {  	// do something else}
Iterationforeach()while()
SummaryValues are like meaningsVariables are like nounsFunctions are like verbsOperators are like grammatical wordsThese are combined to form expressions and statementsStatements are structured in stories, or algorithms with control structures
ExerciseCreate directory for todayCopy rex.php into itLet’s revisit the program and use control structures to format the textUse foreach() to loop through the fileUse IF statements to grab what we wantFormat the text with tags
Two new functionspreg_match($pattern, $string) Two argumentsA regular expression pattern (between slashes “/.../”)A string to apply the expression topreg_replace($pattern,$replacement,$string)Three argumentsA regular expressionA something to replace the matched string withA string to apply the expression to
Regular Expressions. = any character+ = one or more* = 0 or more^ = beginning of the string$ = end of the string[A-Za-z] = character set of all letters() = something to be replaced
AssignmentGrab the Oedipux text Trim the leading and trailing HTML tagsReformat each line using either DIV or P elementsCreate an appropriate CSS stylesheet for the text

Mdst 3559-02-17-php2

  • 1.
    PHP 2MDST 3559: DataestheticsProf. Alvarado02/17/2011
  • 2.
  • 3.
    ReviewPHPVariables, Data Types,FunctionsSee Chapters 2 through 5 of Programming PHPTextEarlier we saw the text handled as a tree (CSS, jQuery)Tuesday we treated the text as an array, a simple linear sequence,
  • 4.
    OverviewToday we willgo back over the basics of PHP To provide a slightly different angle on the subjectTo help clarify some concepts for those new to programmingTo help clarify the “PHP way” for those with experienceThen we will cover two new topicsRegular ExpressionsCreating your own functions
  • 5.
    PHP as alanguagePHP is a programming langague (of course), but it has analogies to natural language as wellThere are parallels to the basic structures of human languagesWhich makes sense: Programming languages are designed to mediate between human and machine language
  • 6.
    What are someelements of natural language?
  • 8.
    Some Elements ofNatural LanguageWordsMeaningsSentencesSomething is said of something elseParts of speech: nouns, verbs, prepositionsHeart of language as language, beyond mere signsParagraphs
  • 9.
    PHP has allof these things
  • 10.
    Values are MeaningsValuesare pieces of dataLanguages are all about doing things with dataData comes in typesTypes include strings and numbersAlso Boolean values (true/false)Values are expressed literally and signified like so:“Hello, World!”5trueThese are the meanings of the language
  • 11.
    Variables are NounsVariablesare words that can have meaning$POTUS = “Obama”;The President of the U.S. is Obama.Like the difference between person and office They are like nouns that refer to things Things being values ...They are always prefixed by $ and are case sensitive
  • 12.
    (Arrays)Arrays are admittedlyweirdBut they can be thought of as words that stand for collections, e.g.The Pittsburgh SteelersThe UVA student bodyThese phrases imply a structureAlbeit much more complicated than arraysBut not much: consider rosters ...
  • 13.
    Functions are VerbsFunctionsare like verbs$food = food_shop($me,$money,$humger_level)Like verbs, they may require arguments and imply a resultVerbs are action wordsConsider transitive versus intransitiveThey are not prefixed by $They are not case sensitiveThey are followed by parentheses
  • 14.
    FunctionsVerbs have implicitarguments and effectsSubjects, objects, indirect objects, are like argumentsIntransitive verbs are like functions that don’t take an argumentOr, it is implicit (the subject)Functions like verbs imply actions that produce effectsPerson A: He ran for office.Person B: And ... ?
  • 15.
    ExpressionsExpressions are likephrases that combine nouns and verbs5(5 + 10) / 36“Tina” . “ is my cat”;file($url)$fooAll expressions result in a value50.4166666 ...Tina is my cat[the array of the file][whatever $foo was last set to]
  • 16.
    StatementsStatements are likesentences. They combine one or more expressions.$my_cat = “Tina”;$x = 2+2;They say something about somethingMy Cat is Tina.$foois 2+2 (is 5)The verb “to be” is an assignment operator ...They are always punctuated by a semi-colon
  • 17.
    OperatorsExpressions and statementsare built out of words by combining them with grammatical words, such as prepositions and conjunctionsIam in the house.I own a catanda dog.Operators are like the grammatical wordsThey don’t have meanings, they have functionsThey don’t reference values (i.e. data), they do things with values
  • 18.
    OperatorsArithmeticAddition, subtraction, division,multiplication, etc.StringConcatenationAssignmentX is YLogicalIs X Y?Is X related to Y in some specified way?
  • 19.
    StructuresStructures, or controlstructures, are like stories or narrative patternsBuilt-in functions control conditions and iterationRepetition and branching
  • 20.
    Conditionsif / elseif/elseif ($x == ‘foo’) { // do something} elseif ($x == ‘bar’) { // do something else } else { // do something else}
  • 21.
  • 22.
    SummaryValues are likemeaningsVariables are like nounsFunctions are like verbsOperators are like grammatical wordsThese are combined to form expressions and statementsStatements are structured in stories, or algorithms with control structures
  • 23.
    ExerciseCreate directory fortodayCopy rex.php into itLet’s revisit the program and use control structures to format the textUse foreach() to loop through the fileUse IF statements to grab what we wantFormat the text with tags
  • 24.
    Two new functionspreg_match($pattern,$string) Two argumentsA regular expression pattern (between slashes “/.../”)A string to apply the expression topreg_replace($pattern,$replacement,$string)Three argumentsA regular expressionA something to replace the matched string withA string to apply the expression to
  • 25.
    Regular Expressions. =any character+ = one or more* = 0 or more^ = beginning of the string$ = end of the string[A-Za-z] = character set of all letters() = something to be replaced
  • 26.
    AssignmentGrab the Oedipuxtext Trim the leading and trailing HTML tagsReformat each line using either DIV or P elementsCreate an appropriate CSS stylesheet for the text