PHP - How Do I Add Children To Xml Using Domdocument And Xpath?
Code: [Select]
$domdoc=new DOMDocument(); $domdoc->formatOutput=TRUE; $empty_cart_xml= '<Order> <Cart> <Items> <Item>1</Item> <Item>2</Item> <Item>3</Item> </Items> </Cart> </Order>'; $domdoc->loadXML($empty_cart_xml); print $domdoc->saveXML()."<hr/>"; //works up to this point $xpath=new DOMXPath($domdoc); $items=$xpath->query('Order/Cart/Items'); foreach($itemses AS $items) { $items->appendChild($domdoc->createElement('Item','4')); } print $domdoc->saveXML(); All I want to do is to add a new Item to Items. What am I doing wrong? Similar TutorialsSo here's what I'm trying to do, and I haven't found any clear tutorials on how to properly navigate a DOMDocument object, at least not in the strict sense of PHP. I'm building a web scraper, I've had it working for some time now using more traditional methods (a combination of string manipulation and clever regex). I've been told xpath can be much faster and more reliable for what I need. Sold. Let's say I'm parsing a forum. This forum separates each reply in a post with a set of <li></li> with a class of "message" Code: [Select] <li class="message"> // Stuff here </li> <li class="message"> // Stuff here </li> So far so good. These list items contain all the formatting for each post, including user info and the message text. Each sitting in it's own div. Code: [Select] <li class="message"> <div class="user info"> User info here </div> <div class="message text"> Message text here </div> </li> <li class="message"> <div class="user info"> User info here </div> <div class="message text"> Message text here </div> </li> Still with me? Good. With this bit of code I can select each message list item block and iterate over all the sub nodes inside. Code: [Select] $items = $xpath->query("//li[starts-with(@class, 'message')]"); for ($i = 0; $i < $items->length; $i++) { echo $items->item($i)->nodeValue . "\n"; } This produces a basic text dump of the entire forum. Close, but not what I need. What I'm trying to do is as follows Select all the class="message" list items [done] Once those have been selected, run another $xpath->query to select the child nodes which contain the user info and message text Step one is done, step two is what is confusing me. How can I run a new query based on the output from the first query? Thanks guys Hi all, I am pretty new to php and I am having an issue trying to load an XML document. When ever I try to use Xpath it negates all the code below the line, including the HTML, and returns a white page. here is my code: Code: [Select] <html> <head> <?php $xpath = new DOMXPath("structure.xml"); ?> <body> hello world </body> </html> I checked phpinfo() and I have both the DOM and XPath enables and installed. I have also tried using just DOM and that worked so it is only Xpath that is not working. Ideas? Thank you James S Delete ... need to change host .. id Name Owner 1 Root 0 2 Child 1 3 Child 1 4 Level-2-Child 2 So, I want to get an element, then get all elements that are either direct or indirect children of it. So - getChildren(2) should return 2 and 4, because 4 is a direct child of 2. And getChildren(1) should return 1, 2, 3, 4 because all items are a child of root. I'm pretty sure it needs to be done with a recursive function. Can someone help me out? how do i find out if a parent has any children? for example id - name - parent_id 1 - title1 - 0 (parent) 2 - title2 - 0 (parent) 3 - link1 - 1 (child) 4 - link2 - 1 (child) 5 - link3 - 2 (child) 5 - link4 - 2 (child) the above has 2 parent with 2 links each. so.. if an id has no "parent_id" pointing to it must be a child if an id has "parent_id" pointing to it must be a parent i have a list Code: [Select] <ul> <li><a href="">'.$link.'</a></li> <li><a href="" class="subTitle">'.$title.'</a> <ul class="subLink"> <li><a href="">'.$link.'</a></li> </ul> </li> </ul> so i want to do something like if id has no "parent_id" pointing to it, it is a $link if id has "parent_id" pointing to it, it is a $title any thoughts thanks in a table cell i have a select statement with options from 1 to 10. Onchange (if they select 3), i want to display a subform in the same table cell where the person can add the for the three children name (Textfield) sex (select: M/F) date of birth (select for day, select for month and select for year) currently, i've tried something with javascript but it's only saves the child_id and parent_id and does not save the rest. Moreover i have no clue how to populate the date of birth. Please if you have any solutions, tell me! Any help is very much appreciated! My parser: <?php if (isset($_GET['formSubmit'])) { $option = $_GET['option']; $option = array_values($option); if (!empty($option)){ $xml = simplexml_load_file('differences.xml'); $i = 0; $count = count($option); ?> <table> <tr> <td>Item</td> <td>Code</td> <td>Type</td> <td>Level</td> </tr> <?php while($i < $count) { $selected = $xml->xpath("//item[contains(@name,'".$option[$i]."')]"); echo "<tr>"; echo "<td>".$selected[0]['name']."</td>"; echo "<td>".$selected[0]['code']."</td>"; echo "<td>".$selected[0]['type']."</td>"; echo "<td>".$selected[0]['requiredLevel']."</td>"; echo "</tr>"; $i++; } ?> </table> This works great however requiredLevel is showing nothing. Here is what is stored in the $selected array: Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [buildingName] => EiffelTower [code] => lM [type] => building ) [requiredLevel] => 5 [cost] => 5000 [built] => 03/31/1889 => SimpleXMLElement Object ( [@attributes] => Array ( [itemClass] => EiffelTower_construct ) ) [defaultItem] => SimpleXMLElement Object ( [@attributes] => Array ( [amount] => 1 [name] => iron ) ) [finishedReward] => iron [image] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [loadClass] => mc [name] => construct_0 [url] => /buildings/eiffel_tower.swf ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [loadClass] => mc [name] => construct_1 [url] => /buildings/eiffel_tower.swf ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [loadClass] => mc [name] => built_0 [url] => /buildings/eiffel_tower.swf ) ) [3] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => icon [url] => buildings/eiffel_tower.png ) ) [4] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => startIcon [url] => /buildings/eiffel_tower.png ) ) [5] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => halfIcon [url] => /buildings/eiffel_tower.png ) ) [6] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => completeIcon [url] => /buildings/eiffel_tower.png ) ) ) [constructionUI] => /buildings/Construct_eiffel_tower.swf [countryCard] => france ) My XML: <element> <item code="lM" name="snowman2010" type="building"> <requiredLevel>5</requiredLevel> <cost>5000</cost> <built>03/31/1889</built> <storageType itemClass="EiffelTower_construct"/> <defaultItem amount="1" name="iron"/> <finishedReward>iron</finishedReward> <image loadClass="mc" name="construct_0" url="/buildings/eiffel_tower.swf"/> <image loadClass="mc" name="construct_1" url="/buildings/eiffel_tower.swf"/> <image loadClass="mc" name="built_0" url="/buildings/eiffel_tower.swf"/> <image name="icon" url="/buildings/eiffel_tower.png"/> <image name="startIcon" url="/buildings/eiffel_tower.png"/> <image name="halfIcon" url="/buildings/eiffel_tower.png"/> <image name="completeIcon" url="/buildings/eiffel_tower.png"/> <constructionUI>/buildings/eiffel_tower.swf</constructionUI> <countryCard>france</countryCard> </item> Using the established code pattern in my parser.php how can I print out requiredLevel? The output of my array is mighty confusing! [/code] Hi all, I need some help here. Currently I am using 2 functions. 1) To call out the 'academic levels' 2) To call out the 'subjects' which matches to the specific 'academic level' However, I am stucked in the codes. Please view my picture attachment, my question is, how do I assigned 'red box (Pre-School)' to 'red box (subjects)' and so on...What are the codes or tweaks that I should make so that it will look like 'what do I want to achieve.jpg' My process and execution $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die(mysqli_error($dbc)); //Run query $tutor_id = mysqli_real_escape_string($dbc, $_GET['tutor_id']); $query = "SELECT tl.level_id, tl.level_name, ts.subject_id, ts.subject_name, tsl.subject_level_id, IF(tosl.tutor_id='{$tutor_id}', 1, 0) as checked FROM tutor_level AS tl INNER JOIN tutor_subject_level AS tsl USING (level_id) INNER JOIN tutor_subject AS ts USING (subject_id) LEFT JOIN tutor_overall_level_subject AS tosl ON tosl.subject_level_id = tsl.subject_level_id AND tosl.tutor_id = '{$tutor_id}' ORDER BY tl.level_id, ts.subject_name"; $sql = mysqli_query($dbc, $query) or die(mysqli_error($dbc)); $query1 = "SELECT tl.level_id, tl.level_name, IF(tslvl.tutor_id='{$tutor_id}', 1, 0) as checked FROM tutor_level AS tl LEFT JOIN tutor_selected_level AS tslvl ON tslvl.level_id = tl.level_id AND tslvl.tutor_id='{$tutor_id}' ORDER BY tl.level_id, tl.level_name"; $sql1 = mysqli_query($dbc, $query1) or die(mysqli_error($dbc)); //Process the results $checkboxes = ''; //Create variable for output $current_level_id = false; //Flag to check when records change level while($data = mysqli_fetch_array($sql)) //Iterate throug the DB results { if($current_level_id != $data['level_id']) //Determine if this level is different from the last { print_r ($data); $subjectCheckboxes .= createSubjectCheckboxes($subject_data, 5); $current_level_id = $data['level_id']; $subject_data = array(); } //Add the current record to the $level_data array $subject_data[] = $data; } //$checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); while($data1 = mysqli_fetch_array($sql1)) { print_r ($data1); $levelCheckboxes .= createLevelCheckboxes($level_data, 5); $level_data = array(); $level_data[] = $data1; } //Call the createLevelCheckboxes() function to generate the HTML for the LAST level records $levelCheckboxes .= createLevelCheckboxes($level_data, 5); $subjectCheckboxes .= createSubjectCheckboxes($subject_data, 5); My functions function createLevelCheckboxes($levelArray, $columns) { if(count($levelArray)==0) { return false; } $htmlOutput = ''; foreach($levelArray as $data1) { //Display level header row $levelID = $levelArray[0]['level_id']; $levelName = $levelArray[0]['level_name']; $checked = ($data1['checked'] == 1) ? ' checked="checked"' : ''; $htmlOutput .= "<tr>\n"; $htmlOutput .= "<th colspan=\"{$columns}\" style=\"text-align:left;padding-top:15px;\">"; $htmlOutput .= "<input name=\"level[]\" type=\"checkbox\" id=\"level_{$levelID}\" type=\"checkbox\" {$checked} value=\"{$levelID}\">"; $htmlOutput .= "<span class=\"zone_text_enlarge\"><label for=\"level_{$levelID}\">{$levelName}</label></span>"; $htmlOutput .= "</th>\n"; $htmlOutput .= "</tr>\n"; } return $htmlOutput; } function createSubjectCheckboxes($subjectArray, $columns) { //Display each subject $recordCount = 0; foreach($subjectArray as $data) { //Increment counter $recordCount++; //Start new row if needed, 1/5 = R1 --> So create a new row if ($recordCount % $columns == 1) { $htmlOutput .= "<tr>\n"; } //Display the record $subjectID = $data['subject_level_id']; $subjectName = $data['subject_name']; $checked = ($data['checked'] == 1) ? ' checked="checked"' : ''; $htmlOutput .= " <td>\n"; $htmlOutput .= " <input name=\"subject_level[]\" class=\"subject_a\" type=\"checkbox\" {$checked}"; $htmlOutput .= " id=\"subject_level_{$subjectID}\" value=\"{$subjectID}\"/>\n"; $htmlOutput .= " <label for=\"subject_level_{$subjectID}\" class=\"subject_1\">{$subjectName}</label>\n"; $htmlOutput .= "</td>\n"; //Close row if needed, 5/5 = 0 --> So close the row if ($recordCount % $columns == 0) { $htmlOutput .= "</tr>\n"; } } //Close last row if needed if ($recordCount % $columns != 0) { $htmlOutput .= "</tr>\n"; } return $htmlOutput; } Hi everyone, I am having trouble with the last() function in xpath . I want to get the text3. The HTML looks like this: Code: [Select] div id="body"> <br> <br> text1 <hr> text2 <br> <br> text3 So far I have: Code: [Select] $lastdata= $simplexml->xpath("//div[@id='body']/following-sibling::node [last()]"); This is not working. I would appreciate any help. Thank you in advance, Bill I am having trouble obtaining the second table in this HTML code: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><html> <head> <meta http-equiv="Pragma" content="no-cache"> <title>Entity Information</title> <link rel="stylesheet" href="documents/CORP/default.css" media="screen" type="text/css"> <link rel="stylesheet" href="documents/CORP/infotable.css" media="screen" type="text/css"> </head> <body> <div class="headings"> <h1 class="dos_heading1">Company Information </h1> <BR> <h2 class="dos_heading2"> </h2> <h3 class="page_heading">Company Information</h3> <p class="DtMsg">The information contained in this database is current through September 10, 2010.</p> </div> <hr noshade width="100%"> <center> <div class="highlight">Selected Company Name: 1 PARK ROW, LLC</div> <table summary="This table contains status information for the selected entity."> <caption> Selected Company Status Information </caption> <tr> <th>Current Company Name:</th> <td>1 PARK ROW, LLC</td> </tr> <tr> <th>Initial Filing Date:</th> <td>JANUARY 22, 1997</td> </tr> <tr> <th>County:</th> <td>NASSAU</td> </tr> <tr> <th>Jurisdiction:</th> <td>NEW JERSEY </td> </tr> <tr> <th>Entity Type:</th> <td>DOMESTIC LIMITED LIABILITY COMPANY</td> </tr> <tr> <th>Current Company Status:</th> <td>ACTIVE </td> </tr> </table> <BR> <table id="tblAddr" summary="This table contains address information for the selected entity."> <caption>Selected Entity Address Information</caption> <tr> <th scope="col" id="c1" class="leftalign"><span class="rmvbold">Address</span></th> </tr> <tr> <td headers="c1"> C/O ELECTRONICS INC.<br> 2355 PARK ROW<br> NEW BRUNSWICK, NEW YORK, 15538 </td> </tr> <tr> <th scope="col" id="c4" class="leftalign">Registered Agent</th> </tr> <tr> <td headers="c1"> NONE </td> </tr> </table> <br> <p style="width:50%"> </p> <div id="divStockContainer"> <h4 id="capStock">*Stock Information</h4> <div id="divStock"> <table id="tblStock" cellpadding="0" cellspacing="6"> <tr> <th># of Shares</th> <th>Type of Stock</th> <th>$ Value per Share</th> </tr> <tr> <td> </td> <td>No Information Available</td> <td> </td> </tr> </table> </div> <p id="pStockBlurb">*Stock information is applicable to domestic business corporations.</p> </div> <div id="divHistNmContainer"> <h4 id="capNmHist">Name History</h4> <div id="divNmHist"> <table id="tblNameHist" cellpadding="0" cellspacing="6"> <tr> <th class="FileDt">Filing Date</th> <th class="NameType">Name Type</th> <th class="CorpName">Company Name</th> </tr> <tr> <td class="FileDt">JAN 22, 1997</td> <td class="NameType">Actual</td> <td class="CorpName">1 PARK ROW, LLC</td> </tr> </table> </div> <p id="pFictName"> </p> </div> </center> </body> </html> <script language='javascript' src='https://a12.alphagodaddy.com/hosting_ads/gd01.js'></script></script> I can get the top part with this: /*** a new dom object ***/ $dom = new domDocument; /*** load the html into the object ***/ $dom->loadHTML($html2); /*** discard white space ***/ $dom->preserveWhiteSpace = false; /*** the table by its tag name ***/ $tables = $dom->getElementsByTagName('table'); /*** get all rows from the table ***/ $rows = $tables->item(0)->getElementsByTagName('tr'); /*** loop over the table rows ***/ foreach ($rows as $row) { /*** get each column by tag name ***/ $cols = $row->getElementsByTagName('td'); /*** echo the values ***/ echo $cols->item(0)->nodeValue.'<br />'; echo $cols->item(1)->nodeValue.'<br />'; echo $cols->item(2)->nodeValue; echo '<hr />'; } } Any help would be appreciated I dont even know where to start to echo the 2nd table in the html. Thanks. Hello, I recently moved hosts and upgraded to PHP 7.4.10. Suddenly, one of my sites is having issues with XSL views. The software creator claims this is an issue with XSL in PHP. I am unsure of what to check to troubleshoot this. Would anyone have an opinion on my issue? If not, please let me know if I should be posting somewhere else altogether. Thanks in advance - Quote
xmlXPathCompOpEval: function function not found The view.xsl file: Quote
<xsl:value-of select="php:function( 'SobiPro::AlternateLink', $rssUrl, 'application/atom+xml', $sectionName )"/>
I am trying to parse a blogspot feed using xpath but it doesnt seem to be working with anything that I try. I am not sure if it is because of the namespaces or what but I was hoping someone could help me. Here is the code: $xml = simplexml_load_file('http://feeds.feedburner.com/blogspot/MKuf'); $next = $xml->xpath("//link[@rel='next']"); print_r($next); This is just returning an empty array and it should not be. I tried it doing just link or just entry and it still is returning empty. The only one I can run on it that works is *. Any help is appreciated. Hi all I am trying to get the lat and long properties from the googlemaps geocoding api. $xml=simplexml_load_file($url); if ($xml === false) { echo "Failed loading XML\n"; foreach(libxml_get_errors() as $error) { echo "\t", $error->message; } } else{ $path = $xml->xpath( "/GeocodeResponse/result/geometry/location"); $lat = $path->lat; $lng = $path->lng; echo $lat; echo $lng; $sql1 = "UPDATE tbl_clubs set lat='$lat',lng='$lng' where club_id =$id"; echo $sql1; $result1 = mysqli_query($dbConn,$sql1) or die($mysqli_error($dbConn)); } This is the XML I am using <GeocodeResponse> <status>OK</status> <result> <type>establishment</type> <type>point_of_interest</type> <type>stadium</type> <formatted_address>Aldridge Rd, Perry Barr, Birmingham B42 2ET, UK</formatted_address> <address_component> </address_component> <address_component> </address_component> <address_component> </address_component> <address_component> <long_name>West Midlands</long_name> <short_name>West Midlands</short_name> <type>administrative_area_level_2</type> <type>political</type> </address_component> <address_component> <long_name>England</long_name> <short_name>England</short_name> <type>administrative_area_level_1</type> <type>political</type> </address_component> <address_component> <long_name>United Kingdom</long_name> <short_name>GB</short_name> <type>country</type> <type>political</type> </address_component> <address_component> <long_name>B42 2ET</long_name> <short_name>B42 2ET</short_name> <type>postal_code</type> </address_component> <geometry> <location> <lat>52.5196698</lat> <lng>-1.8986236</lng> </location> <location_type>GEOMETRIC_CENTER</location_type> <viewport> <southwest> <lat>52.5183208</lat> <lng>-1.8999726</lng> </southwest> <northeast> <lat>52.5210188</lat> <lng>-1.8972746</lng> </northeast> </viewport> </geometry>
But I am getting the following response Notice: Trying to get property of non-object in /home/sites/1a/9/95f15f28a6/public_html/results/getLatLng.php on line 22 I am guessing my path is wrong, any guidance would be great Hi all, I'm sure I'm making this far more difficult than I need to... I've got an xml document... <library id="1"> <lname>Lib1</name> <book id="1"> <title>book 1</title> <author>Author 1</author> </book> <book id="2"> <title>book 2</title> <author>Author 2</author> </book> </library> I can access the nested elements using xpath like : $result = $xml->xpath('//book'); foreach($result as $books) { echo $books->title; } How would I do this for the attributes? If I specify I want the attributes in the xpath query I can't get at the elements... I'm trying to turn this xml file into a simple relational database... A library table and a book table. So I need the library id (attribute) and the name(nested element) for one insert query - and the book id, title, author and the library id for the other. Anyone got any idea? Cheers John good evening dear php-freaks,
hope you are all right.
My tactic is as follows:
1. i run requests to the openstreetmap-endpoint- (see below) and i try three different APIs per request isn't that easy on ressources and 2. I don't know how to work with the results that i gather from the OpenStreetmap-Endpoint
as of the first point: - workin on the endpoint of OSM-Overpass-API.... see my approach: <?php /** * OSM Overpass API with PHP SimpleXML / XPath * * PHP Version: 5.4 - Can be back-ported to 5.3 by using 5.3 Array-Syntax (not PHP 5.4's square brackets) */ // // 1.) Query an OSM Overpass API Endpoint // $query = 'node ["amenity"~".*"] (38.415938460513274,16.06338500976562,39.52205163048525,17.51220703125); out;'; $context = stream_context_create(['http' => [ 'method' => 'POST', 'header' => ['Content-Type: application/x-www-form-urlencoded'], 'content' => 'data=' . urlencode($query), ]]); # please do not stress this service, this example is for demonstration purposes only. $endpoint = 'http://overpass-api.de/api/interpreter'; libxml_set_streams_context($context); $start = microtime(true); $result = simplexml_load_file($endpoint); printf("Query returned %2\$d node(s) and took %1\$.5f seconds.\n\n", microtime(true) - $start, count($result->node)); // // 2.) Work with the XML Result //
so far so good: with this i get a bunch of data.....
<?xml version="1.0" encoding="UTF-8"?> <osm version="0.6" generator="Osmosis SNAPSHOT-r26564" xapi:planetDate="2014-10-07T15:42:02Z" xmlns:xapi="http://jxapi.openstreetmap.org/"> <node id="251652819" version="6" timestamp="2013-10-19T14:03:10Z" uid="1198089" user="GeorgeKaplan" changeset="18434238" lat="48.8527413" lon="2.3333559"> <tag k="dispensing" v="yes"/> <tag k="website" v="http://www.pharmacie-paris-citypharma.fr/"/> <tag k="name" v="Pharmacie Citypharma in downtown paris"/> <tag k="amenity" v="pharmacy"/> </node> <node id="251774849" version="9" timestamp="2014-07-28T21:28:26Z" uid="92075" user="Art Penteur" changeset="24411346" lat="48.8468043" lon="2.3696423"> <tag k="phone" v="0143430996"/> <tag k="dispensing" v="yes"/> <tag k="name" v="Pharmacie de la Rapée in downtown paris"/> <tag k="amenity" v="pharmacy"/> <tag k="opening_hours" v="Mo-Fr 08:30-20:30; Sa 09:00-19:30"/> </node> <node id="263262912" version="3" timestamp="2014-07-28T21:37:24Z" uid="92075" user="Art Penteur" changeset="24411346" lat="48.8446917" lon="2.3101829"> <tag k="dispensing" v="yes"/> <tag k="amenity" v="pharmacy"/> </node>
what is aimed: I am trying to filter the records based on the attributes that i find in the dataset, <tag k="name" v="blahblahblah"/> field.
I have been looking around and the classical way to do it its easy, however because of my poor skills in doing anything Is it possible to apply xml filtering for tags that look like this <tag k="dispensing" v="yes"/> ones that do not have the <tag></tag>
.....format. Also how can i filter the records when each child of the node has different attributes,like v, <tag k="name">Pharmacie in Paris-downtown - Rapée-metro-station</tag>
i have had a quick look at the PHP-SimpleXML and the XPath-approach: it may help me in achieving what is aimed.
but at the moment - i think i got stuck.
i greatly appreciated hints and some ideas that may fit her.
have a great day. - yours dil_bert Edited December 1, 2019 by dil_bert hi, im trying to parse this xml file : xml.gamebookers.com/sport /football.xml_attr.xml i want to echo on my page like this : league name 1 match 1 of league 1 odds odds odds match 2 of league 1 odds odds odds . . league name 2 match 1 of league 2 odds odds odds match2 of league 2 odds odds odds . . this is my code so far <?php $xml=simplexml_load_file('http://xml.gamebookers.com/sports/football.xml_attr.xml'); $league=$xml->xpath('//event/..'); // leagues refers to element<group> $matches=$xml->xpath('//bettype[@name="Versus (with Draw)"]/..'); // shows matches name (team versus team) $odds=$xml->xpath('//event/bettype[@name="Versus (with Draw)"]/bet'); //odds of matches 1 x 2 $leaguecount=count($league); $matchescount=count($matches); $oddscount=count($odds); $i=0; while ($i<$leaguecount){ echo $league[$i]['name'].'<br>'; $i++; } echo '<br><br>'; $i=0; while ($i<$matchescount){ echo $matches[$i]['name'].'<br>'; $i++; } $i=0; while ($i<$oddscount){ echo $odds[$i]['odd'].'<br>'; $i++; } ?> it prints this: http://www.mh724.com/school/xp.php so i need something like that: echo league[$i][mathces[$i][odds[$i] // like arrays of array but it does not work of course any help will highly appreciated :shrug: with regardS I have some code $doc = new DOMDocument(); $doc->loadHTML( '<html> <head><title>Test</title></head> <body></body></html>' ); $doc->encoding = 'iso-8859-1'; file_put_contents('test.html', $doc->saveHTML()); when i view the output file i get <html><head><title>Test</title></head><body></body></html> all on one line is there no way of having it format it like the original source code so that its not all bunched together? Is there any reason that people can think as to why DOMDocument::saveHTML would remove the following: Code: [Select] <![if !vml]> <img src="someimage.jpg" /> <![endif]> A little clarification... This HTML comment tag is used in my company's email newsletter code and is necessary to make Outlook 2007 behave properly. For whatever reason, saveHTML strips it out. I know that this doesn't conform to HTML standards and I'm guessing that that is why it is being stripped. BUT, from reading on the internet, saveHTML can produce junk html code anyways. Any help is appreciated. Hi guys, Just starting to play with PHP Domdocument, only to fail at the very first step: <?php $html = 'test/php/somefile.html' ; if(!empty($html)){ $dom_1 = new domDocument ; $dom_1->loadHTML($html) ; $links = $dom_1->getElementsByTagName('li') ; foreach ( $links as $link) { // echo $link ; echo $link->nodeValue, PHP_EOL; } } ?> When I visit it in a browser I get a WSOD, what am I missing? |