I’ve
PHP Tutorials
Whether just getting started or an expert, this vast collection of PHP tutorials will help you create dynamic content for powerful web-based applications in no time.
This article will help you design a web site which makes visitors feel like it was designed just for
This article will help you design a web site which makes visitors feel like it was designed just for
This article will help you design a web site which makes visitors feel like it was designed just for
By Joe Stump on September 7, 2000 Recently, at work I was given the job of learning XML. OK, so it wasn’t technically XML, it was RDF, but I found that PHP’s XML parsing functions worked just the same. At work I parsed out DMOZ (http://www.dmoz.org) but for simplicity I…
By Joe Stump on September 7, 2000 <?php // handles the attributes for opening tags // $attrs is a multidimensional array keyed by attribute // name and having the value of that attribute function startElement($parser, $name, $attrs=”){ global $open_tags, $temp, $current_tag; $current_tag = $name; if ($format = $open_tags[$name]){ switch($name){ case ‘STORY’: echo ‘New Story: ‘; break; default: break; } } } // $current_tag lets us know what tag we are currently // dealing with – we use that later in the characterData // function. // // when we see a </STORY> we know that it is time to // flush our temp variables and prepare to move onto // the next one function endElement($parser, $name, $attrs=”){ global $close_tags, $temp, $current_tag; if ($format = $close_tags[$name]){ switch($name){ case ‘STORY’: return_page($temp); $temp = ”; break; default: break; } } } // this function is passed data between elements // theu $data would equal ‘Title Here’ // in the line <TITLE>Title Here</TITLE> function characterData($parser, $data){ global $current_tag, $temp, $catID; switch($current_tag){…
By Joe Stump on September 7, 2000 <?php function return_page(){ global $temp; echo ‘o <A HREF=”‘.$temp[‘url’].'”>’.$temp[‘title’].'</A><BR>’; } // what are we parsing? $xml_file = ‘slashdot.xml’; // declare the character set – UTF-8 is the default $type = ‘UTF-8’; // create our parser $xml_parser = xml_parser_create($type); // set some parser options xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true); xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, ‘UTF-8’); // this tells PHP what functions to call when it finds an element // these funcitons also handle the element’s attributes xml_set_element_handler($xml_parser, ‘startElement’,’endElement’); // this tells PHP what function to use on the character data xml_set_character_data_handler($xml_parser, ‘characterData’); if (!($fp = fopen($xml_file, ‘r’))) { die(“Could not open $xml_file for parsing!n”); } // loop through the file and parse baby! while ($data = fread($fp, 4096)) { if (!($data = utf8_encode($data))) { echo ‘ERROR’.”n”; } if (!xml_parse($xml_parser, $data, feof($fp))) { die(sprintf( “XML error: %s at line %dnn”, xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); } } xml_parser_free($xml_parser); ?> Now this is what happens: PHP starts parsing…
By Joe Stump on January 3, 2001 I try and wade through as many postings on PHP General as possible throughout the day. Everything from “What does $$var mean?” to “How to I redirect someone to another page?” pop up. Two common problems pop up on the list frequently, one…
By Joe Stump on January 3, 2001 The first thing to note is that we have two tables here with a many to one relationship. “Many to one what?” What this means is that there can be “many” links in “one” category, thus creating a “many to one” relationship. Other…
By Joe Stump on January 3, 2001 “Whoa! You took some into from one table and some info from another to make a psuedo table!” – pretty cool, huh? And the best thing about it is that if I want to change the name of category “Linux” to “FooBar” I…