i
PHP Variables
PHP Data Types
PHP Echo & Print
PHP Strings
PHP Numbers
PHP Constants
PHP Operators
PHP if...else...elseif Statements
Switch Statement
PHP Loops
PHP Arrays
Superglobals
PHP Coding Standards
PHP Form Handling
PHP Form Validation
PHP URLs Validation
PHP Form Required Validation
Complete Form Example
PHP File Functions Open/Read
PHP File Create/Write
PHP File Upload
PHP Cookies Handling
PHP Session Handling
PHP filter_var() Function
PHP Validation Filters
PHP Sanitization Filters
Using Filters
Filters Advanced
JSON
PHP Date and Time
MySQL Database
MySQL Connect
MySQL Commands-Creating a Table
MySQL Commands-Inserting The data
MySQL Commands-Prepared Statement
MySQL Commands-Selecting The Data
MySQL Commands-Where and Order By
MySQL Commands-Deleting And Updating The Data
PHP-OOP Introduction
PHP-Classes/Objects
PHP-Constructor/Destructor
PHP-Access Modifiers
PHP-Inheritance
PHP-Inheritance and Protected Access Modifier
PHP-Overriding Inherited Methods
PHP-Final keyword
PHP-Abstract Classes
PHP-Constants
PHP-Traits
PHP-Static Methods and Properties
Introduction to Functions
Defining A function
Returning Values From A Function
Dynamic Function Calls
Variable Scope
Understanding Arguments Or Parameters
Testing For A Function Existence
Returning Multiple Values From A Function
Making practical Use By Building Code Libraries For Code Re-usability
Using Include() And Require()
Expat parser is an event-based XML parser and it returns the XML data as a series of events.
For example: Martin will be reported as three series of event by XML Expat.
Start element : to
Start CDATA section, value : Martin
Close element : to
Let us get detailed explanation of Expat parsing and in-built functions for Expat parsing.
$parser=xml_parser_create(); // To Initialize the parser
// Function that is used at the start of an element
function start($parser,$element_name,$element_attrs) {
switch($element_name) {
case "NOTE":
echo "-- Note --
";
break;
case "TO":
echo "To: ";
break;
case "FROM":
echo "From: ";
break;
case "HEADING":
echo "Heading: ";
break;
case "BODY":
echo "Message: ";
}
}
// Function that is used at the end of an element
function stop($parser,$element_name) {
echo "
";
}
// Function that is used when finding character data
function char($parser,$data) {
echo $data;
}
// To Specify element handler
xml_set_element_handler($parser,"start","stop");
// To Specify data handler
xml_set_character_data_handler($parser,"char");
// To open XML file
$fp=fopen("Reminder.xml","r");
// To Read data
while ($data=fread($fp,4096)) {
xml_parse($parser,$data,feof($fp)) or
die (sprintf("XML Error: %s at line %d",
xml_error_string(xml_get_error_code($parser)),
xml_get_current_line_number($parser)));
}
xml_parser_free($parser);
?>
Let us understand the example in detail:
xml_parser_create() function is used to initialize the XML parser.
Different event handlers are managed using functions.
xml_set_element_handler() function is used to specify the functions to be executed while parsing the opening and closing tags.
xml_set_character_data_handler() function is used to specify the functions that will be execute while parsing character data.
xml_parse() function will parse Reminder.xml file.
xml_error_string() function converts the XML error into a text description.
xml_parser_free() function is used to release the memory that is allocated while initialization.
Don't miss out!