Presentation is loading. Please wait.

Presentation is loading. Please wait.

Advanced PHP & RSS Utilizing XML, RSS, and PHP. XML (eXtensible Markup Language) XML is the language of all RSS feeds and subscriptions XML is basically.

Similar presentations


Presentation on theme: "Advanced PHP & RSS Utilizing XML, RSS, and PHP. XML (eXtensible Markup Language) XML is the language of all RSS feeds and subscriptions XML is basically."— Presentation transcript:

1 Advanced PHP & RSS Utilizing XML, RSS, and PHP

2 XML (eXtensible Markup Language) XML is the language of all RSS feeds and subscriptions XML is basically a way of separating data from aesthetics XML is a “poor man’s” database XML is similar to HTML, but you get to create the tags “Self-describing” data

3 XML Presentation XML can be used to present content in different formats: XHTML/HTML, PDF, Graphics, Mobile Devices, Text, MS Office

4 XML Syntax ELEMENT CHILD ELEMENT ATTRIBUTE … VALUE Matthews Darell TEXT (Darell) 20120904 START TAG 29.95 JavaScript Lessons Neilson, Jason END TAG ELEMENT CHILD ELEMENT ATTRIBUTE … VALUE Matthews Darell TEXT (Darell) 20120904 START TAG 29.95 JavaScript Lessons Neilson, Jason END TAG

5 XML as a Database XML data organized into elements, attributes, and values (similar to tables, fields, and elements) Works great for storing around 50 or less attribute/value pairs Often used in JS slideshows (1 XML for settings, 1 for photos used) and Flash animations (1 XML for settings telling the flash movie what to do)

6 XPath XPath is a language which allows us to quickly access information in an XML document based on our knowledge of its structure /child::student/child::student[$number=‘0001’]Example: movie.xml, movie.php, actor.php

7 XML Address Book Create addressbook.php, which lists your name as an, then a horizontal rule Create addressbook.xml, which will include 5 people and their contact information (name, address, city, state, zip, phone, email) Create a drop-down list populated with names pulled from addressbook.xml using SimpleXMLElements. Once the user selects a name, they click “Search” to bring up that person’s contact information on a page called contact.php. The contact.php page should display that person’s contact information, again being pulled from the XML file using the API, in an organized table. All PHP pages should be styled (in any manner you wish) using an external CSS file.

8 XML Address Book addressbook.php contact.php

9 SimpleXML PHP API that allows PHP to interact with XML Create an XML document, then use PHP to parse the document for filtering / querying. SimpleXMLElement is the PHP parsing function Since RSS feeds use XML to describe data in the feed, we can use PHP to parse that feed for our usage, all we need is the feed address and some knowledge of the XML structure. Item, title, description, link Podcasts are RSS feeds with attachments

10 Feed Parsing View the page http://sampsoncctech.info/cis115/feed View the XML source code (notice the element, child elements, attributes, and values) Most RSS feeds follow the same general structure and element/attribute naming convention Use PHP to grab the contents of the feed and place them into an HTML document for styling Use PHP to grab the contents of the feed and place them into an HTML document for styling

11 Feed Styling and Output Once you have PHP gathering the feed data, now use HTML and PHP to style the output simplexmlelementdemoCIS115.php PHP “foreach” statement to loop and grab each feed article and put it into a list where the title is a link to the article channel -> item as $item) { ?> link; ?>"> title; ?> PHP “foreach” statement to loop and grab each feed article and put it into a list where the title is a link to the article channel -> item as $item) { ?> link; ?>"> title; ?>

12 Parsing Other RSS Feeds Find an RSS feed, podcast, or vodcast online with an accessible XML feed source page Use PHP to gather the feed data, then a “foreach” statement to parse each child element of the XML feed Use HTML to style the output of the PHP parsing into an ordered or unordered list

13 PHP Data Types & Operators PHP doesn’t require you to specify data type You can initialize and declare variables in one line $variable = “some value or string”; echo $variable; Data Types: String, Integer, Floating-Point, Exponential, Boolean, NULL

14 PHP Arrays Contains a set of data represented by a single variable Array names are often referred to with array operators ([ ]) at the end of the name $variable = array(“element1”, “element2”, “element3”); $variable[] = “element1”; Declare an array with $variable = array(values): and access elements within the array by using $variable[index];

15 PHP Array Example The following “, count($concerts), “ concerts are scheduled: ”; echo “$concerts[0] ”; echo “$concerts[1] ”; echo “$concerts[2] ”; echo “$concerts[3] ”; ?> The following “, count($concerts), “ concerts are scheduled: ”; echo “$concerts[0] ”; echo “$concerts[1] ”; echo “$concerts[2] ”; echo “$concerts[3] ”; ?>

16 PHP Expressions Expression: a literal value or number Operands: variables and literals contained in an expression Literals: values such as a string or number Operators: symbols such as +, -, *, / that are used in expressions to manipulate operands PHP Operator Types: array, arithmetic, assignment, comparison, logical, special, string

17 Building PHP Expressions Arithmetic Binary Operators: +, -, *, /, % (modulus) arithmeticbinaryoperators.php Arithmetic Unary Operators: ++ (increment), -- (decrement) arithmeticunaryoperators.php, 100countdown.php, 100countup.php Logical Operators: && (AND), || (OR), ! (NOT) logicalexamples.php

18 PHP Cash Register cashregister.htmlcashregister.php

19 Type Casting in PHP Type casting: a way to ensure that a variable is of the correct type $SpeedLimitMiles = “55 mph”; $SpeedLimitKilo = (int) $SpeedLimitMiles * 1.6; echo “$SpeedLimitMiles equals $SpeedLimitKilo.”; To test whether a variable is of a given data type, you should instead use an “is_*()” function is_numeric(), is_string(), is_int(), is_double()

20 Comparison Operator Example Comparison Operators: Comparison Operators:

21 Logical Operator Example Logical Operators: Logical Operators:

22 PHP Do … While Loop Do…While (perform an action while a condition is being met) ”; $num++; } while (($num > 0) && ($num Do…While (perform an action while a condition is being met) ”; $num++; } while (($num > 0) && ($num

23 PHP If…Else…If Conditional If…Else…If (if this happens, do this, else/otherwise, do this) If…Else…If (if this happens, do this, else/otherwise, do this)

24 PHP For Loop For (perform this action for a fixed number of times) ”; } ?> ------------------------------------------------------------------------------------------------------------ ”; } } ?>

25 PHP Nested For Loop Nesting one for loop inside of another to perform vertical and horizontal actions \n”; for ($y=1; $y \n”; for ($x=1; $x ”; echo ($x * $y); echo “ \n”; } echo “ \n”; } echo “ ”; ?>


Download ppt "Advanced PHP & RSS Utilizing XML, RSS, and PHP. XML (eXtensible Markup Language) XML is the language of all RSS feeds and subscriptions XML is basically."

Similar presentations


Ads by Google