SlideShare ist ein Scribd-Unternehmen logo
1 von 26
PHP 2 MDST 3559:  DataestheticsProf. Alvarado02/17/2011
Business VPN?
Review PHP Variables, Data Types, Functions See Chapters 2 through 5 of Programming PHP Text Earlier we saw the text handled as a tree (CSS, jQuery) Tuesday we treated the text as an array, a simple linear sequence,
Overview Today we will go back over the basics of PHP  To provide a slightly different angle on the subject To help clarify some concepts for those new to programming To help clarify the “PHP way” for those with experience Then we will cover two new topics Regular Expressions Creating your own functions
PHP as a language PHP is a programming langague (of course), but it has analogies to natural language as well There are parallels to the basic structures of human languages Which makes sense:  Programming languages are designed to mediate between human and machine language
What are some elements of natural language?
Some Elements of Natural Language Words Meanings Sentences Something is said of something else Parts of speech: nouns, verbs, prepositions Heart of language as language, beyond mere signs Paragraphs
PHP has all of these things
Values are Meanings Values are pieces of data Languages are all about doing things with data Data comes in types Types include strings and numbers Also Boolean values (true/false) Values are expressed literally and signified like so: “Hello, World!” 5 true These are the meanings of the language
Variables are Nouns Variables 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 weird But they can be thought of as words that stand for collections, e.g. The Pittsburgh Steelers The UVA student body These phrases imply a structure Albeit much more complicated than arrays But not much: consider rosters ...
Functions are Verbs Functions are like verbs $food = food_shop($me,$money,$humger_level) Like verbs, they may require arguments and imply a result Verbs are action words Consider transitive versus intransitive They are not prefixed by $ They are not case sensitive They are followed by parentheses
Functions Verbs have implicit arguments and effects Subjects, objects, indirect objects, are like arguments Intransitive verbs are like functions that don’t take an argument Or, it is implicit (the subject) Functions like verbs imply actions that produce effects Person A: He ran for office. Person B: And ... ?
Expressions Expressions are like phrases that combine nouns and verbs 5 (5 + 10) / 36 “Tina” . “ is my cat”; file($url) $foo All expressions result in a value 5 0.4166666 ... Tina is my cat [the array of the file] [whatever $foo was last set to]
Statements Statements are like sentences.   They combine one or more expressions. $my_cat = “Tina”; $x = 2+2; They say something about something My Cat is Tina. $foois 2+2 (is 5) The verb “to be” is an assignment operator ... They are always punctuated by a semi-colon
Operators Expressions and statements are built out of words by combining them with grammatical words, such as prepositions and conjunctions Iam in the house. I own a catanda dog. Operators are like the grammatical words They don’t have meanings, they have functions They don’t reference values (i.e. data), they do things with values
Operators Arithmetic Addition, subtraction, division, multiplication, etc. String Concatenation Assignment X is Y Logical Is X Y? Is X related to Y in some  specified way?
Structures Structures, or control structures, are like stories or narrative patterns Built-in functions control conditions and iteration Repetition and branching
Conditions if / elseif/ else if ($x == ‘foo’) { 	// do something } elseif ($x == ‘bar’) { 	// do something else  } else {   	// do something else }
Iteration foreach() while()
Summary Values are like meanings Variables are like nouns Functions are like verbs Operators are like grammatical words These are combined to form expressions and statements Statements are structured in stories, or algorithms with control structures
Exercise Create directory for today Copy rex.php into it Let’s revisit the program and use control structures to format the text Use foreach() to loop through the file Use IF statements to grab what we want Format the text with tags
Two new functions preg_match($pattern, $string)  Two arguments A regular expression pattern (between slashes “/.../”) A string to apply the expression to preg_replace($pattern,$replacement,$string) Three arguments A regular expression A something to replace the matched string with A 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
Assignment Grab the Oedipux text  Trim the leading and trailing HTML tags Reformat each line using either DIV or P elements Create an appropriate CSS stylesheet for the text

Weitere ähnliche Inhalte

Was ist angesagt?

Prolog Programming Language
Prolog Programming  LanguageProlog Programming  Language
Prolog Programming LanguageReham AlBlehid
 
Introduction to prolog
Introduction to prologIntroduction to prolog
Introduction to prologHarry Potter
 
10 logic+programming+with+prolog
10 logic+programming+with+prolog10 logic+programming+with+prolog
10 logic+programming+with+prologbaran19901990
 
Enhanced E-R diagram
Enhanced E-R diagramEnhanced E-R diagram
Enhanced E-R diagramMayank Jain
 
Cardinality and participation constraints
Cardinality and participation constraintsCardinality and participation constraints
Cardinality and participation constraintsNikhil Deswal
 
Artificial intelligence Prolog Language
Artificial intelligence Prolog LanguageArtificial intelligence Prolog Language
Artificial intelligence Prolog LanguageREHMAT ULLAH
 
24042020_normalization 1.pdf
24042020_normalization 1.pdf24042020_normalization 1.pdf
24042020_normalization 1.pdfShivani139202
 
Lesson 1 function as model
Lesson 1 function as modelLesson 1 function as model
Lesson 1 function as modelrey castro
 
Prolog 01
Prolog 01Prolog 01
Prolog 01saru40
 
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
FUNCTION DEPENDENCY  AND TYPES & EXAMPLEFUNCTION DEPENDENCY  AND TYPES & EXAMPLE
FUNCTION DEPENDENCY AND TYPES & EXAMPLEVraj Patel
 

Was ist angesagt? (18)

Prolog Programming Language
Prolog Programming  LanguageProlog Programming  Language
Prolog Programming Language
 
Introduction to prolog
Introduction to prologIntroduction to prolog
Introduction to prolog
 
10 logic+programming+with+prolog
10 logic+programming+with+prolog10 logic+programming+with+prolog
10 logic+programming+with+prolog
 
Enhanced E-R diagram
Enhanced E-R diagramEnhanced E-R diagram
Enhanced E-R diagram
 
Cardinality and participation constraints
Cardinality and participation constraintsCardinality and participation constraints
Cardinality and participation constraints
 
Functional dependency
Functional dependencyFunctional dependency
Functional dependency
 
Artificial intelligence Prolog Language
Artificial intelligence Prolog LanguageArtificial intelligence Prolog Language
Artificial intelligence Prolog Language
 
Chaps 1-3-ai-prolog
Chaps 1-3-ai-prologChaps 1-3-ai-prolog
Chaps 1-3-ai-prolog
 
Normalization
NormalizationNormalization
Normalization
 
Prolog basics
Prolog basicsProlog basics
Prolog basics
 
24042020_normalization 1.pdf
24042020_normalization 1.pdf24042020_normalization 1.pdf
24042020_normalization 1.pdf
 
Lesson 1 function as model
Lesson 1 function as modelLesson 1 function as model
Lesson 1 function as model
 
Prolog 01
Prolog 01Prolog 01
Prolog 01
 
Ics1019 ics5003
Ics1019 ics5003Ics1019 ics5003
Ics1019 ics5003
 
Introduction to Prolog
Introduction to PrologIntroduction to Prolog
Introduction to Prolog
 
Prolog
PrologProlog
Prolog
 
prolog ppt
prolog pptprolog ppt
prolog ppt
 
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
FUNCTION DEPENDENCY  AND TYPES & EXAMPLEFUNCTION DEPENDENCY  AND TYPES & EXAMPLE
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
 

Andere mochten auch

Mdst3703 2013-09-17-text-models
Mdst3703 2013-09-17-text-modelsMdst3703 2013-09-17-text-models
Mdst3703 2013-09-17-text-modelsRafael Alvarado
 
Mdst3703 2013-08-29-hello-world
Mdst3703 2013-08-29-hello-worldMdst3703 2013-08-29-hello-world
Mdst3703 2013-08-29-hello-worldRafael Alvarado
 
Mdst3703 ontology-overrated-2012-10-16
Mdst3703 ontology-overrated-2012-10-16Mdst3703 ontology-overrated-2012-10-16
Mdst3703 ontology-overrated-2012-10-16Rafael Alvarado
 
Mdst3705 2012-01-22-code-as-language
Mdst3705 2012-01-22-code-as-languageMdst3705 2012-01-22-code-as-language
Mdst3705 2012-01-22-code-as-languageRafael Alvarado
 

Andere mochten auch (8)

Mdst3703 2013-09-17-text-models
Mdst3703 2013-09-17-text-modelsMdst3703 2013-09-17-text-models
Mdst3703 2013-09-17-text-models
 
Mdst 3559-03-22-case-1
Mdst 3559-03-22-case-1Mdst 3559-03-22-case-1
Mdst 3559-03-22-case-1
 
Mdst 3559-04-21-data-2
Mdst 3559-04-21-data-2Mdst 3559-04-21-data-2
Mdst 3559-04-21-data-2
 
Mdst3703 2013-08-29-hello-world
Mdst3703 2013-08-29-hello-worldMdst3703 2013-08-29-hello-world
Mdst3703 2013-08-29-hello-world
 
MDST 3703 F10 Seminar 4
MDST 3703 F10 Seminar 4MDST 3703 F10 Seminar 4
MDST 3703 F10 Seminar 4
 
Mdst3703 ontology-overrated-2012-10-16
Mdst3703 ontology-overrated-2012-10-16Mdst3703 ontology-overrated-2012-10-16
Mdst3703 ontology-overrated-2012-10-16
 
Mdst3705 2012-01-22-code-as-language
Mdst3705 2012-01-22-code-as-languageMdst3705 2012-01-22-code-as-language
Mdst3705 2012-01-22-code-as-language
 
MDST 3703 F10 Studio 9
MDST 3703 F10 Studio 9MDST 3703 F10 Studio 9
MDST 3703 F10 Studio 9
 

Ähnlich wie Mdst 3559-02-17-php2

Systemic Functional Grammar
Systemic Functional Grammar Systemic Functional Grammar
Systemic Functional Grammar Sugeng Hariyanto
 
Mdst3705 2013-02-05-databases
Mdst3705 2013-02-05-databasesMdst3705 2013-02-05-databases
Mdst3705 2013-02-05-databasesRafael Alvarado
 
Syntax 334 lecture 3
Syntax 334 lecture 3Syntax 334 lecture 3
Syntax 334 lecture 3Akashgary
 
Mind map esl 502
Mind map esl 502Mind map esl 502
Mind map esl 502k1hinze
 
Possible Word Representation
Possible Word RepresentationPossible Word Representation
Possible Word Representationchauhankapil
 
Introduction to Distributional Semantics
Introduction to Distributional SemanticsIntroduction to Distributional Semantics
Introduction to Distributional SemanticsAndre Freitas
 
Chart during reading strategies
Chart during reading strategiesChart during reading strategies
Chart during reading strategiesSECCIONDEINGLES
 
Beginners Guide on PHP Programming
Beginners Guide on PHP ProgrammingBeginners Guide on PHP Programming
Beginners Guide on PHP ProgrammingKindle Books
 
Representation of syntax, semantics and Predicate logics
Representation of syntax, semantics and Predicate logicsRepresentation of syntax, semantics and Predicate logics
Representation of syntax, semantics and Predicate logicschauhankapil
 
An Intuitive Natural Language Understanding System
An Intuitive Natural Language Understanding SystemAn Intuitive Natural Language Understanding System
An Intuitive Natural Language Understanding Systeminscit2006
 
Lexical functional grammar (lfg).pptx
Lexical functional grammar (lfg).pptxLexical functional grammar (lfg).pptx
Lexical functional grammar (lfg).pptxjhonalyntizon
 
Nouns (sustantivos)
Nouns (sustantivos)Nouns (sustantivos)
Nouns (sustantivos)Juan Otero
 
Unit-4-Knowledge-representation.pdf
Unit-4-Knowledge-representation.pdfUnit-4-Knowledge-representation.pdf
Unit-4-Knowledge-representation.pdfHrideshSapkota2
 

Ähnlich wie Mdst 3559-02-17-php2 (20)

Systemic Functional Grammar
Systemic Functional Grammar Systemic Functional Grammar
Systemic Functional Grammar
 
Textmining
TextminingTextmining
Textmining
 
Mdst3705 2013-02-05-databases
Mdst3705 2013-02-05-databasesMdst3705 2013-02-05-databases
Mdst3705 2013-02-05-databases
 
Syntax 334 lecture 3
Syntax 334 lecture 3Syntax 334 lecture 3
Syntax 334 lecture 3
 
Mind map esl 502
Mind map esl 502Mind map esl 502
Mind map esl 502
 
Possible Word Representation
Possible Word RepresentationPossible Word Representation
Possible Word Representation
 
Syntax
SyntaxSyntax
Syntax
 
unit -3 part 1.ppt
unit -3 part 1.pptunit -3 part 1.ppt
unit -3 part 1.ppt
 
NLP
NLPNLP
NLP
 
Introduction to Distributional Semantics
Introduction to Distributional SemanticsIntroduction to Distributional Semantics
Introduction to Distributional Semantics
 
Php
PhpPhp
Php
 
Chart during reading strategies
Chart during reading strategiesChart during reading strategies
Chart during reading strategies
 
Beginners Guide on PHP Programming
Beginners Guide on PHP ProgrammingBeginners Guide on PHP Programming
Beginners Guide on PHP Programming
 
Representation of syntax, semantics and Predicate logics
Representation of syntax, semantics and Predicate logicsRepresentation of syntax, semantics and Predicate logics
Representation of syntax, semantics and Predicate logics
 
An Intuitive Natural Language Understanding System
An Intuitive Natural Language Understanding SystemAn Intuitive Natural Language Understanding System
An Intuitive Natural Language Understanding System
 
Lexical functional grammar (lfg).pptx
Lexical functional grammar (lfg).pptxLexical functional grammar (lfg).pptx
Lexical functional grammar (lfg).pptx
 
Syntax
SyntaxSyntax
Syntax
 
Nouns (sustantivos)
Nouns (sustantivos)Nouns (sustantivos)
Nouns (sustantivos)
 
Knowledge Extraction
Knowledge ExtractionKnowledge Extraction
Knowledge Extraction
 
Unit-4-Knowledge-representation.pdf
Unit-4-Knowledge-representation.pdfUnit-4-Knowledge-representation.pdf
Unit-4-Knowledge-representation.pdf
 

Mehr von Rafael Alvarado

Mdst3703 2013-10-08-thematic-research-collections
Mdst3703 2013-10-08-thematic-research-collectionsMdst3703 2013-10-08-thematic-research-collections
Mdst3703 2013-10-08-thematic-research-collectionsRafael Alvarado
 
Mdst3703 2013-10-01-hypertext-and-history
Mdst3703 2013-10-01-hypertext-and-historyMdst3703 2013-10-01-hypertext-and-history
Mdst3703 2013-10-01-hypertext-and-historyRafael Alvarado
 
Mdst3703 2013-09-24-hypertext
Mdst3703 2013-09-24-hypertextMdst3703 2013-09-24-hypertext
Mdst3703 2013-09-24-hypertextRafael Alvarado
 
Mdst3703 2013-09-12-semantic-html
Mdst3703 2013-09-12-semantic-htmlMdst3703 2013-09-12-semantic-html
Mdst3703 2013-09-12-semantic-htmlRafael Alvarado
 
Mdst3703 2013-09-10-textual-signals
Mdst3703 2013-09-10-textual-signalsMdst3703 2013-09-10-textual-signals
Mdst3703 2013-09-10-textual-signalsRafael Alvarado
 
Mdst3703 2013-09-05-studio2
Mdst3703 2013-09-05-studio2Mdst3703 2013-09-05-studio2
Mdst3703 2013-09-05-studio2Rafael Alvarado
 
Mdst3703 2013-09-03-plato2
Mdst3703 2013-09-03-plato2Mdst3703 2013-09-03-plato2
Mdst3703 2013-09-03-plato2Rafael Alvarado
 
UVA MDST 3703 2013 08-27 Introduction
UVA MDST 3703 2013 08-27 IntroductionUVA MDST 3703 2013 08-27 Introduction
UVA MDST 3703 2013 08-27 IntroductionRafael Alvarado
 
MDST 3705 2012-03-05 Databases to Visualization
MDST 3705 2012-03-05 Databases to VisualizationMDST 3705 2012-03-05 Databases to Visualization
MDST 3705 2012-03-05 Databases to VisualizationRafael Alvarado
 
Mdst3705 2013-02-26-db-as-genre
Mdst3705 2013-02-26-db-as-genreMdst3705 2013-02-26-db-as-genre
Mdst3705 2013-02-26-db-as-genreRafael Alvarado
 
Mdst3705 2013-02-19-text-into-data
Mdst3705 2013-02-19-text-into-dataMdst3705 2013-02-19-text-into-data
Mdst3705 2013-02-19-text-into-dataRafael Alvarado
 
Mdst3705 2013-02-12-finding-data
Mdst3705 2013-02-12-finding-dataMdst3705 2013-02-12-finding-data
Mdst3705 2013-02-12-finding-dataRafael Alvarado
 
Mdst3705 2013-01-29-praxis
Mdst3705 2013-01-29-praxisMdst3705 2013-01-29-praxis
Mdst3705 2013-01-29-praxisRafael Alvarado
 
Mdst3705 2013-01-31-php3
Mdst3705 2013-01-31-php3Mdst3705 2013-01-31-php3
Mdst3705 2013-01-31-php3Rafael Alvarado
 
Mdst3705 2013-01-24-php2
Mdst3705 2013-01-24-php2Mdst3705 2013-01-24-php2
Mdst3705 2013-01-24-php2Rafael Alvarado
 
Mdst3705 2012-01-15-introduction
Mdst3705 2012-01-15-introductionMdst3705 2012-01-15-introduction
Mdst3705 2012-01-15-introductionRafael Alvarado
 
Mdst3703 graph-theory-11-20-2012
Mdst3703 graph-theory-11-20-2012Mdst3703 graph-theory-11-20-2012
Mdst3703 graph-theory-11-20-2012Rafael Alvarado
 
Mdst3703 maps-and-timelines-2012-11-13
Mdst3703 maps-and-timelines-2012-11-13Mdst3703 maps-and-timelines-2012-11-13
Mdst3703 maps-and-timelines-2012-11-13Rafael Alvarado
 
Mdst3703 culturomics-2012-11-01
Mdst3703 culturomics-2012-11-01Mdst3703 culturomics-2012-11-01
Mdst3703 culturomics-2012-11-01Rafael Alvarado
 

Mehr von Rafael Alvarado (20)

Mdst3703 2013-10-08-thematic-research-collections
Mdst3703 2013-10-08-thematic-research-collectionsMdst3703 2013-10-08-thematic-research-collections
Mdst3703 2013-10-08-thematic-research-collections
 
Mdst3703 2013-10-01-hypertext-and-history
Mdst3703 2013-10-01-hypertext-and-historyMdst3703 2013-10-01-hypertext-and-history
Mdst3703 2013-10-01-hypertext-and-history
 
Mdst3703 2013-09-24-hypertext
Mdst3703 2013-09-24-hypertextMdst3703 2013-09-24-hypertext
Mdst3703 2013-09-24-hypertext
 
Presentation1
Presentation1Presentation1
Presentation1
 
Mdst3703 2013-09-12-semantic-html
Mdst3703 2013-09-12-semantic-htmlMdst3703 2013-09-12-semantic-html
Mdst3703 2013-09-12-semantic-html
 
Mdst3703 2013-09-10-textual-signals
Mdst3703 2013-09-10-textual-signalsMdst3703 2013-09-10-textual-signals
Mdst3703 2013-09-10-textual-signals
 
Mdst3703 2013-09-05-studio2
Mdst3703 2013-09-05-studio2Mdst3703 2013-09-05-studio2
Mdst3703 2013-09-05-studio2
 
Mdst3703 2013-09-03-plato2
Mdst3703 2013-09-03-plato2Mdst3703 2013-09-03-plato2
Mdst3703 2013-09-03-plato2
 
UVA MDST 3703 2013 08-27 Introduction
UVA MDST 3703 2013 08-27 IntroductionUVA MDST 3703 2013 08-27 Introduction
UVA MDST 3703 2013 08-27 Introduction
 
MDST 3705 2012-03-05 Databases to Visualization
MDST 3705 2012-03-05 Databases to VisualizationMDST 3705 2012-03-05 Databases to Visualization
MDST 3705 2012-03-05 Databases to Visualization
 
Mdst3705 2013-02-26-db-as-genre
Mdst3705 2013-02-26-db-as-genreMdst3705 2013-02-26-db-as-genre
Mdst3705 2013-02-26-db-as-genre
 
Mdst3705 2013-02-19-text-into-data
Mdst3705 2013-02-19-text-into-dataMdst3705 2013-02-19-text-into-data
Mdst3705 2013-02-19-text-into-data
 
Mdst3705 2013-02-12-finding-data
Mdst3705 2013-02-12-finding-dataMdst3705 2013-02-12-finding-data
Mdst3705 2013-02-12-finding-data
 
Mdst3705 2013-01-29-praxis
Mdst3705 2013-01-29-praxisMdst3705 2013-01-29-praxis
Mdst3705 2013-01-29-praxis
 
Mdst3705 2013-01-31-php3
Mdst3705 2013-01-31-php3Mdst3705 2013-01-31-php3
Mdst3705 2013-01-31-php3
 
Mdst3705 2013-01-24-php2
Mdst3705 2013-01-24-php2Mdst3705 2013-01-24-php2
Mdst3705 2013-01-24-php2
 
Mdst3705 2012-01-15-introduction
Mdst3705 2012-01-15-introductionMdst3705 2012-01-15-introduction
Mdst3705 2012-01-15-introduction
 
Mdst3703 graph-theory-11-20-2012
Mdst3703 graph-theory-11-20-2012Mdst3703 graph-theory-11-20-2012
Mdst3703 graph-theory-11-20-2012
 
Mdst3703 maps-and-timelines-2012-11-13
Mdst3703 maps-and-timelines-2012-11-13Mdst3703 maps-and-timelines-2012-11-13
Mdst3703 maps-and-timelines-2012-11-13
 
Mdst3703 culturomics-2012-11-01
Mdst3703 culturomics-2012-11-01Mdst3703 culturomics-2012-11-01
Mdst3703 culturomics-2012-11-01
 

Mdst 3559-02-17-php2

  • 1. PHP 2 MDST 3559: DataestheticsProf. Alvarado02/17/2011
  • 3. Review PHP Variables, Data Types, Functions See Chapters 2 through 5 of Programming PHP Text Earlier we saw the text handled as a tree (CSS, jQuery) Tuesday we treated the text as an array, a simple linear sequence,
  • 4. Overview Today we will go back over the basics of PHP To provide a slightly different angle on the subject To help clarify some concepts for those new to programming To help clarify the “PHP way” for those with experience Then we will cover two new topics Regular Expressions Creating your own functions
  • 5. PHP as a language PHP is a programming langague (of course), but it has analogies to natural language as well There are parallels to the basic structures of human languages Which makes sense: Programming languages are designed to mediate between human and machine language
  • 6. What are some elements of natural language?
  • 7.
  • 8. Some Elements of Natural Language Words Meanings Sentences Something is said of something else Parts of speech: nouns, verbs, prepositions Heart of language as language, beyond mere signs Paragraphs
  • 9. PHP has all of these things
  • 10. Values are Meanings Values are pieces of data Languages are all about doing things with data Data comes in types Types include strings and numbers Also Boolean values (true/false) Values are expressed literally and signified like so: “Hello, World!” 5 true These are the meanings of the language
  • 11. Variables are Nouns Variables 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
  • 12. (Arrays) Arrays are admittedly weird But they can be thought of as words that stand for collections, e.g. The Pittsburgh Steelers The UVA student body These phrases imply a structure Albeit much more complicated than arrays But not much: consider rosters ...
  • 13. Functions are Verbs Functions are like verbs $food = food_shop($me,$money,$humger_level) Like verbs, they may require arguments and imply a result Verbs are action words Consider transitive versus intransitive They are not prefixed by $ They are not case sensitive They are followed by parentheses
  • 14. Functions Verbs have implicit arguments and effects Subjects, objects, indirect objects, are like arguments Intransitive verbs are like functions that don’t take an argument Or, it is implicit (the subject) Functions like verbs imply actions that produce effects Person A: He ran for office. Person B: And ... ?
  • 15. Expressions Expressions are like phrases that combine nouns and verbs 5 (5 + 10) / 36 “Tina” . “ is my cat”; file($url) $foo All expressions result in a value 5 0.4166666 ... Tina is my cat [the array of the file] [whatever $foo was last set to]
  • 16. Statements Statements are like sentences. They combine one or more expressions. $my_cat = “Tina”; $x = 2+2; They say something about something My 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. Operators Expressions and statements are built out of words by combining them with grammatical words, such as prepositions and conjunctions Iam in the house. I own a catanda dog. Operators are like the grammatical words They don’t have meanings, they have functions They don’t reference values (i.e. data), they do things with values
  • 18. Operators Arithmetic Addition, subtraction, division, multiplication, etc. String Concatenation Assignment X is Y Logical Is X Y? Is X related to Y in some specified way?
  • 19. Structures Structures, or control structures, are like stories or narrative patterns Built-in functions control conditions and iteration Repetition and branching
  • 20. Conditions if / elseif/ else if ($x == ‘foo’) { // do something } elseif ($x == ‘bar’) { // do something else } else { // do something else }
  • 22. Summary Values are like meanings Variables are like nouns Functions are like verbs Operators are like grammatical words These are combined to form expressions and statements Statements are structured in stories, or algorithms with control structures
  • 23. Exercise Create directory for today Copy rex.php into it Let’s revisit the program and use control structures to format the text Use foreach() to loop through the file Use IF statements to grab what we want Format the text with tags
  • 24. Two new functions preg_match($pattern, $string) Two arguments A regular expression pattern (between slashes “/.../”) A string to apply the expression to preg_replace($pattern,$replacement,$string) Three arguments A regular expression A something to replace the matched string with A 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. Assignment Grab the Oedipux text Trim the leading and trailing HTML tags Reformat each line using either DIV or P elements Create an appropriate CSS stylesheet for the text