PHP - Replicate Nodes
Using HTML5 and CSS3, and jQuery is available.
I have a form block enclosing several hidden div blocks. jQuery will unhide a div block on selecting a control node -- presented as a tab.
I need to have a form input appear in more than one div block. That is, the HTML has four tabs, each tab making visible one of four div blocks. On one of the four div blocks, a specific form input is present.
I need for this specific input to also appear in one of the other div blocks. I want the one input, coded in one of the div blocks, to be "seen" and be operational in another div block -- but not have the HTML code for it located or duplicated there.
I thought about adding another input tag with the same name and showing the same value, but that is unworkable as it stands. I do not want to replicate or duplicate or otherwise make two separate inputs. But...
My current plan is to have two inputs of the same name, but the input in the hidden div block is disabled. By being disabled, the value of it will not be submitted. When the second div block becomes visible, the first input is disabled and the second is enabled. I would also need to copy the newly entered value into the other same-named input.
Could there be a better way?
Another way would be to move the specific input outside of the div blocks so that it is always visible. But I do not care to have this input visible for all the div blocks when each becomes visible.
Edited by bsmither, 08 January 2015 - 12:21 AM. Similar TutorialsThis is my current code (actually it's heavily based off of a code a fellow phpfreak made. Basically, this makes it easy to put up images. When I want to put up a linkable image, I simply need to add to the image_links my subfolder, and add to the image_description my description. Anyways, here it is, you can try and run it yourself: Code: [Select] <?php $rows_per_page = 2; $cols_per_page = 2; $image_href = '<a href=/'; $image_links = array('otherstuff/nature>', 'otherstuff/volcanoes>', 'otherstuff/papersupplies>''); $img_srcs = '<img src="https://s3.amazonaws.com/imgs/'; $images = array(); for($i = 1; $i < 10; $i++) { $images[$i] = $i; } $image_ending = '.png" height="200" width="200" /></a>'; $image_break = '<br /><div class="timeago"><div id="submitted">submitted </div>'; $image_descriptions = array('<abbr class="timeago" title="2011-03-13T07:24:17Z"></abbr></div>', '<abbr class="timeago" title="2011-03-13T07:24:17Z"></abbr></div>', '<abbr class="timeago" title="2011-03-13T07:24:17Z"></abbr></div>'); $total_images = count($images); $images_per_page = $rows_per_page * $cols_per_page; $total_images = count($images); $total_pages = ceil($total_images / $images_per_page); $current_page = (int) $_GET['page']; if($current_page<1 || $current_page>$total_pages) { $current_page = 1; } //Get records for the current page $page_image_links = array_splice($image_links, ($current_page-1)*$images_per_page, $images_per_page); $page_images = array_splice($images, ($current_page-1)*$images_per_page, $images_per_page); $page_image_descriptions = array_splice($image_descriptions, ($current_page-1)*$images_per_page, $images_per_page); $slots = "<table border=\"0\">"; for($row=0; $row<$rows_per_page; $row++) { $slots .= "<tr>"; for($col=0; $col<$cols_per_page; $col++) { $imgIdx = ($row * $rows_per_page) + $col; $img = (isset($page_images[$imgIdx])) ? "{$image_href}{$page_image_links[$imgIdx]}{$img_srcs}{$page_images[$imgIdx]}{$image_ending}{$image_break}{$page_image_descriptions[$imgIdx]}" : ' '; $slots .= "<td class='tables'>$img</td>"; } $slots .= "</tr>"; } $slots .= "</table>"; //Create pagination links $first = "First"; $prev = "Prev"; $next = "Next"; $last = "Last"; if($current_page>1) { $prevPage = $current_page - 1; $first = "<a href=\"w4rmoemfdoiemroifmeromfxdnxvl.php?page=1\">First</a>"; $prev = "<a href=\"w4rmoemfdoiemroifmeromfxdnxvl.php?page={$prevPage}\">Prev</a>"; } if($current_page<$total_pages) { $nextPage = $current_page + 1; $next = "<a href=\"w4rmoemfdoiemroifmeromfxdnxvl.php?page={$nextPage}\">Next</a>"; $last = "<a href=\"w4rmoemfdoiemroifmeromfxdnxvl.php?page={$total_pages}\">Last</a>"; } ?> <html> <title></title> <head><style type="text/css"> #submitted {color: #888888; font-family:Verdana, Geneva, sans-serif; font-size: .8em; float:left;} .tables {padding-left: 20px; padding-right: 20px;} .timeago {color: #888888; font-family:Verdana, Geneva, sans-serif; font-size: .8em; float:right;} </style><script src="/static/jquery-1.5.1.js" type="text/javascript"></script> <script src="/static/jquery.timeago.js" type="text/javascript"></script> <script type="text/javascript"> jQuery(document).ready(function() { jQuery("abbr.timeago").timeago(); });</script></head> <body> <h2>Here are the records for page <?php echo $current_page; ?></h2> <ul> <?php echo $slots; ?> </ul> Page <?php echo $current_page; ?> of <?php echo $total_pages; ?> <br /> <?php echo "view mo {$next}"; ?> </body> </html> --------------------------------------------------------------------- Now, I want to prepare for the long run. If I ever get up to say 1000 images, it's gonna take a while to parse 1000 image_links and 1000 image_descriptions, so instead, I want it to be read off of a database instead. I know low-level mySQL, I can usually understand the syntax. My problem is, I can never wrap my head around the logic. You can lock me in a week for a week and I still wouldn't be able to figure it out. But show me the code, and I'd say "I get it!" Can anyone please help me out, rather by giving a rough code or good thorough advice to carry it out? I'd prefer a good rough code but I'll take anything at this point :[ Thanks! MOD EDIT: [code] . . . [/code] tags added. Hi all, i have a very large xml file containing 2000 child nodes. i am using DOMDocument to read xml data but it shows whole data at once, i want to fetch first 20 or 30 nodes first time and then rest leave for pagination. is there any way to do so. to read only first few records from xml file. Thanks in advance... Hello... I want to draw a nodes with arcs by using PHP. Is there any package available to do this? My nodes values are gene name. Please help me......... Hi I have searched around for a solution to this and either fail to grasp how to get it to work or just cannot find the correct solution. I have the following XML file: Code: [Select] <?xml version="1.0" encoding="UTF-8"?> <root> <product> <id>153</id> <images> <image id="1"> <url>http://www.mysite.com/product/images/1322.jpg</url> <title> <en>Book 1</en> </title> </image> <image id="2"> <url>http://www.mysite.com/product/images/1321.jpg</url> <title> <en>Book 2</en> </title> </image> <image id="3"> <url>http://www.mysite.com/product/images/1316.jpg</url> <title> <en>Book 3</en> </title> </images> </product> <product> <id>154</id> <images> <image id="1"> <url>http://www.mysite.com/product/images/1322.jpg</url> <title> <en>Book 1</en> </title> </image> <image id="2"> <url>http://www.mysite.com/product/images/1321.jpg</url> <title> <en>Book 2</en> </title> </image> <image id="3"> <url>http://www.mysite.com/product/images/1316.jpg</url> <title> <en>Book 3</en> </title> </images> </product> </root> $xml = 'example.xml'; // URL for feed. try{ $feed = new SimpleXMLElement($xml, null, true); }catch(Exception $e){ echo $e->getMessage(); exit; } $sql = 'INSERT INTO images (`id`, `url`) VALUES '; foreach($feed->property as $property){ $sql .= sprintf( "\n('%d', '%s'),", $property->id, mysql_real_escape_string($property->images->image->url) ); } $sql = rtrim($sql, ',') . ';'; What I need to do is loop through each of the image url nodes and insert them into my DB with the relevant id. Can somebody point me in the right direction with this please its driving me nuts! Regards GT good day dear phpfreaks.
I am new to PHP's SimpleXML. i want to work with SimpleXML on OSM-files. The original version of this question was derived from he OSM Data parsing to get the nodes with child https://stackoverflow.com/questions/16129184/osm-data-parsing-to-get-the-nodes-with-child
I am thankful that hakre offered a great example in the comments that makes a overwhelming goal: how to get more out of it: I want to filter the data to get the nodes with special category. Here is sample of the OSM data I want to get the whole schools within an area. The first script runs well - but now I want to refine the search and add more tags. Finally I want to store all into MySQL. So we need to make some XML parsing with PHP:
The following is a little OSM Overp
Quote
since i am learning - i break down the code into pieces...For my question, the second part is more interesting here. That is querying the XML data we have already. Again - as mentioned above: This is most easily done with xpath, the used PHP XML library is based on libxml which supports XPath 1.0 which covers the various querying needs very well. The following example lists all schools and tries to obtain their names as well.
# get all school nodes with xpath //node[tag[@k = "amenity" and @v = "school"]] This line says: Give me all node elements that have a tag element inside which has the k attribute value "amenity" and the v attribute value "school". Explanation: This is the condition we have to filter out those nodes that are tagged with amenity school. Further on xpath is used again - a second time: now relative to those school nodes to see if there is a name and if so to fetch it: Therefore we use the foreach-syntax:
foreach ($schools as $index => $school)
tag[@k = "name"]/@v'
tag[@k = "name"]/@v' Because not all school nodes have a name, a default string is provided for display purposes by adding it to the (then empty) result array:
list($name) = $school->xpath('tag[@k = "name"]/@v') + ['(unnamed)'];
Query returned 907 node(s) and took 1.10735 seconds. goal: to get out even more important data - see here Key:contact - OpenStreetMap Wiki
Well - we are already extracting the name: If we want to have more data then we just have to run a few more xpath queries inside our loop for all the address keys and the website. So - additionally: we do not have to forget to look for the website key additional to contact:website. cf: https://wiki.openstreetmap.org/wiki/Key:website conclusio: well - i think that i need to extend the xpath requests within the loop where xpath is used again, now relative to those school nodes to see if there is a name and if so to fetch it:
tag[@k = "name"]/@v' i did some further tess and found out very interesting things
$query = 'node
$context = stream_context_create(['http' => [
# please do not stress this service, this example is for demonstration purposes only.
$result = simplexml_load_file($endpoint);
//
# get all school nodes with xpath
$query = 'node
$context = stream_context_create(['http' => [
$endpoint = 'http://overpass-api.de/api/interpreter';
$result = simplexml_load_file($endpoint);
me/martin/dev/php/o1.php on line 68
33 School(s) found:
so far so good : if i add some lines in the part 2 i run into errors... -see below: i want to get more data out of it: - and coded like so;
{ note - within the part 2 that works with the XML-Result.
//
# get all school nodes with xpath
contact:phone I will dig into all documents and come back later the weekend... and report all the findings well - i think that i need to extend the xpath requests within the loop where xpath is used again, now relative to those school nodes to see if there is a name and if so to fetch it:
tag[@k = "name"]/@v'
more infos Hi! I'm having trouble accessing data with simpleXML_load_file I have a working script that loads an XML-file and outputs in a proprietary format that I've written, but for some reason I can't get it to work with this second set of XML-files. Loading the file seems to work fine. I load the file into a variable, and can print the contents of the file using echo $xml -> asXML(); However, when I try to access a single node using: echo $xml->{'SOAP-ENV:Envelope'}->{'SOAP-ENV:Body'}->Order->OrderHeader->OrderNumber->BuyerOrderNumber;I get the following error: Notice: Trying to get property of non-object in C:\www\convert_uio.php on line 28 XML-file looks as follows: <?xml version="1.0" encoding="utf-8"?> <SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <SOAP-ENV:Header> <nseps:endpoints SOAP-ENV:mustUnderstand="true" xmlns:nseps="urn:schemas-IBX:/docs/endpoint.nsendpoint"> <nseps:to> <nseps:address>8b51fc8c-7aba-1000-bbbe-c0a878330001</nseps:address> </nseps:to> <nseps:from> <nseps:address>1b0ad9d6-7a05-1000-a43c-c0a878330001</nseps:address> </nseps:from> </nseps:endpoints> <nsprop:properties SOAP-ENV:mustUnderstand="true" xmlns:nsprop="urn:schemas-IBX:/docs/property.nsproperty"> <nsprop:identity>fb1797dbb1f14a179482b1bb53bc7c14</nsprop:identity> <nsprop:sentAt>2014-09-02T00:00:00+01:00</nsprop:sentAt> <nsprop:topic>Order</nsprop:topic> </nsprop:properties> </SOAP-ENV:Header> <SOAP-ENV:Body> <Order xmlns="rrn:org.xcbl:schemas/xcbl/v3_5/xcbl35.xsd"> <OrderHeader> <OrderNumber> <BuyerOrderNumber>E14124673</BuyerOrderNumber> </OrderNumber> <OrderIssueDate>20140902T00:00:00+01:00</OrderIssueDate> <OrderReferences> <AccountCode> <Reference> <RefNum>no_unoslo</RefNum> </Reference> </AccountCode> </OrderReferences> <Purpose> <PurposeCoded>Original</PurposeCoded> </Purpose> <RequestedResponse> <RequestedResponseCoded>NoAcknowledgementNeeded</RequestedResponseCoded> </RequestedResponse> <OrderType> <OrderTypeCoded>PurchaseOrder</OrderTypeCoded> </OrderType> <OrderCurrency> <Currency> <CurrencyCoded>NOK</CurrencyCoded> </Currency> </OrderCurrency> <OrderLanguage> <Language LanguageDependent="false"> <LanguageCoded>no</LanguageCoded> </Language> </OrderLanguage> <OrderDates> <RequestedDeliverByDate>20140904T00:00:00+01:00</RequestedDeliverByDate> </OrderDates> <OrderParty> <BuyerParty> <Party> <PartyID> <Identifier> <Agency> <AgencyCoded>AssignedByBuyerOrBuyersAgent</AgencyCoded> </Agency> <Ident>no_uio</Ident> </Identifier> </PartyID> <NameAddress> <Name1>xxxxxxxxxxxxx</Name1> <Name2>xxxxxxxxxxxxx</Name2> <POBox>xxxxx</POBox> <PostalCode>NO-0316</PostalCode> <City>Oslo</City> <Country> <CountryCoded>NO</CountryCoded> </Country> </NameAddress> <OrderContact> <Contact> <ContactName>Some Name</ContactName> <ContactFunction> <ContactFunctionCoded>PurchasingContact</ContactFunctionCoded> </ContactFunction> <ListOfContactNumber> <ContactNumber> <ContactNumberValue>email@email.no</ContactNumberValue> <ContactNumberTypeCoded>EmailAddress</ContactNumberTypeCoded> </ContactNumber> <ContactNumber> <ContactNumberValue>+4700000000</ContactNumberValue> <ContactNumberTypeCoded>TelephoneNumber</ContactNumberTypeCoded> </ContactNumber> </ListOfContactNumber> </Contact> </OrderContact> </Party> </BuyerParty> <BuyerTaxInformation> <PartyTaxInformation> <TaxIdentifier> <Identifier> <Agency> <AgencyCoded>Other</AgencyCoded> <AgencyCodedOther>VAT Number</AgencyCodedOther> </Agency> <Ident>00000000</Ident> </Identifier> </TaxIdentifier> </PartyTaxInformation> </BuyerTaxInformation> <SellerParty> <Party> <PartyID> <Identifier> <Agency> <AgencyCoded>AssignedByBuyerOrBuyersAgent</AgencyCoded> </Agency> <Ident>8b51fc8c-7aba-1000-bbbe-c0a878330001</Ident> </Identifier> </PartyID> <NameAddress> <Name1>Name 2</Name1> <Street>Adress</Street> <PostalCode> 0314</PostalCode> <City>OSLO</City> <Country> <CountryCoded>NO</CountryCoded> </Country> </NameAddress> <OrderContact> <Contact> <ContactName>N/A</ContactName> <ListOfContactNumber> <ContactNumber> <ContactNumberValue>email</ContactNumberValue> <ContactNumberTypeCoded>EmailAddress</ContactNumberTypeCoded> </ContactNumber> <ContactNumber> <ContactNumberValue>47 0000000</ContactNumberValue> <ContactNumberTypeCoded>FaxNumber</ContactNumberTypeCoded> </ContactNumber> </ListOfContactNumber> </Contact> </OrderContact> </Party> </SellerParty> <ShipToParty> <Party> <PartyID> <Identifier> <Agency> <AgencyCoded>AssignedByBuyerOrBuyersAgent</AgencyCoded> </Agency> <Ident /> </Identifier> </PartyID> <NameAddress> <Name1>Name</Name1> <Name2>Name2 </Name2> <Street>Adress</Street> <StreetSupplement1>0318 Oslo</StreetSupplement1> <PostalCode>NO-0562</PostalCode> <City>OSLO</City> <Country> <CountryCoded>NO</CountryCoded> </Country> </NameAddress> <OrderContact> <Contact> <ContactName>Name</ContactName> <ContactFunction> <ContactFunctionCoded>PurchasingContact</ContactFunctionCoded> </ContactFunction> <ListOfContactNumber> <ContactNumber> <ContactNumberValue>emamil</ContactNumberValue> <ContactNumberTypeCoded>EmailAddress</ContactNumberTypeCoded> </ContactNumber> <ContactNumber> <ContactNumberValue>+470000000</ContactNumberValue> <ContactNumberTypeCoded>TelephoneNumber</ContactNumberTypeCoded> </ContactNumber> </ListOfContactNumber> </Contact> </OrderContact> <ReceivingContact> <Contact> <ContactName>Name</ContactName> <ContactFunction> <ContactFunctionCoded>PurchasingContact</ContactFunctionCoded> </ContactFunction> <ListOfContactNumber> <ContactNumber> <ContactNumberValue>email</ContactNumberValue> <ContactNumberTypeCoded>EmailAddress</ContactNumberTypeCoded> </ContactNumber> <ContactNumber> <ContactNumberValue>+4700000000</ContactNumberValue> <ContactNumberTypeCoded>TelephoneNumber</ContactNumberTypeCoded> </ContactNumber> </ListOfContactNumber> </Contact> </ReceivingContact> </Party> </ShipToParty> <BillToParty> <Party> <PartyID> <Identifier> <Agency> <AgencyCoded>AssignedByBuyerOrBuyersAgent</AgencyCoded> </Agency> <Ident>no_uio</Ident> </Identifier> </PartyID> <NameAddress> <Name1>Name</Name1> <Name2>Adress</Name2> <POBox>adress2</POBox> <PostalCode>NO-0316</PostalCode> <City>Oslo</City> <County /> <District>9908:971035854</District> <Country> <CountryCoded>NO</CountryCoded> </Country> </NameAddress> <OrderContact> <Contact> <ContactName>Name</ContactName> <ContactFunction> <ContactFunctionCoded>PurchasingContact</ContactFunctionCoded> </ContactFunction> <ListOfContactNumber> <ContactNumber> <ContactNumberValue>email</ContactNumberValue> <ContactNumberTypeCoded>EmailAddress</ContactNumberTypeCoded> </ContactNumber> <ContactNumber> <ContactNumberValue>+470000000</ContactNumberValue> <ContactNumberTypeCoded>TelephoneNumber</ContactNumberTypeCoded> </ContactNumber> </ListOfContactNumber> </Contact> </OrderContact> </Party> </BillToParty> </OrderParty> <OrderTermsOfDelivery> <TermsOfDelivery> <TermsOfDeliveryFunctionCoded>Other</TermsOfDeliveryFunctionCoded> <TermsOfDeliveryFunctionCodedOther>Other</TermsOfDeliveryFunctionCodedOther> <TransportTermsCoded>Other</TransportTermsCoded> <TransportTermsCodedOther>DDP</TransportTermsCodedOther> <ShipmentMethodOfPaymentCoded>Other</ShipmentMethodOfPaymentCoded> <ShipmentMethodOfPaymentCodedOther>Other</ShipmentMethodOfPaymentCodedOther> <TransportDescription /> </TermsOfDelivery> </OrderTermsOfDelivery> <OrderHeaderNote /> </OrderHeader> <OrderDetail> <ListOfItemDetail> <ItemDetail> <BaseItemDetail> <LineItemNum> <BuyerLineItemNum>1</BuyerLineItemNum> </LineItemNum> <LineItemType> <LineItemTypeCoded>Item</LineItemTypeCoded> </LineItemType> <ItemIdentifiers> <PartNumbers> <SellerPartNumber> <PartNum> <PartID>1000000000001</PartID> </PartNum> </SellerPartNumber> <ManufacturerPartNumber> <PartID /> </ManufacturerPartNumber> </PartNumbers> <ItemDescription>Normal frakt, pris 20 NOK</ItemDescription> </ItemIdentifiers> <TotalQuantity> <Quantity> <QuantityValue>1</QuantityValue> <UnitOfMeasurement> <UOMCoded>EA</UOMCoded> </UnitOfMeasurement> </Quantity> </TotalQuantity> <OffCatalogFlag>false</OffCatalogFlag> </BaseItemDetail> <PricingDetail> <ListOfPrice> <Price> <UnitPrice> <UnitPriceValue>20</UnitPriceValue> <Currency> <CurrencyCoded>NOK</CurrencyCoded> </Currency> <UnitOfMeasurement> <UOMCoded>EA</UOMCoded> </UnitOfMeasurement> </UnitPrice> <PriceBasisQuantity> <Quantity> <QuantityValue>1</QuantityValue> <UnitOfMeasurement> <UOMCoded>EA</UOMCoded> </UnitOfMeasurement> </Quantity> </PriceBasisQuantity> </Price> </ListOfPrice> <Tax> <TaxFunctionQualifierCoded>Tax</TaxFunctionQualifierCoded> <TaxCategoryCoded>StandardRate</TaxCategoryCoded> <TaxTypeCoded>ValueAddedTax</TaxTypeCoded> <TaxPercent>.00</TaxPercent> <TaxableAmount>20.00</TaxableAmount> <TaxAmount>.00</TaxAmount> </Tax> <TotalValue> <MonetaryValue> <MonetaryAmount>20.00</MonetaryAmount> </MonetaryValue> </TotalValue> </PricingDetail> <DeliveryDetail> <ListOfScheduleLine> <ScheduleLine> <Quantity> <QuantityValue>1</QuantityValue> <UnitOfMeasurement> <UOMCoded>EA</UOMCoded> </UnitOfMeasurement> </Quantity> <RequestedDeliveryDate>20140904T00:00:00+01:00</RequestedDeliveryDate> </ScheduleLine> </ListOfScheduleLine> </DeliveryDetail> </ItemDetail> <ItemDetail> <BaseItemDetail> <LineItemNum> <BuyerLineItemNum>2</BuyerLineItemNum> </LineItemNum> <LineItemType> <LineItemTypeCoded>Item</LineItemTypeCoded> </LineItemType> <ItemIdentifiers> <PartNumbers> <SellerPartNumber> <PartNum> <PartID>9788258312007</PartID> </PartNum> </SellerPartNumber> <ManufacturerPartNumber> <PartID /> </ManufacturerPartNumber> </PartNumbers> <ItemDescription>Hovedtariffavtalen i staten 1. mai 2014 - 30. april 2016 (p.100kr)</ItemDescription> </ItemIdentifiers> <TotalQuantity> <Quantity> <QuantityValue>2</QuantityValue> <UnitOfMeasurement> <UOMCoded>EA</UOMCoded> </UnitOfMeasurement> </Quantity> </TotalQuantity> <OffCatalogFlag>false</OffCatalogFlag> </BaseItemDetail> <PricingDetail> <ListOfPrice> <Price> <UnitPrice> <UnitPriceValue>100</UnitPriceValue> <Currency> <CurrencyCoded>NOK</CurrencyCoded> </Currency> <UnitOfMeasurement> <UOMCoded>EA</UOMCoded> </UnitOfMeasurement> </UnitPrice> <PriceBasisQuantity> <Quantity> <QuantityValue>1</QuantityValue> <UnitOfMeasurement> <UOMCoded>EA</UOMCoded> </UnitOfMeasurement> </Quantity> </PriceBasisQuantity> </Price> </ListOfPrice> <Tax> <TaxFunctionQualifierCoded>Tax</TaxFunctionQualifierCoded> <TaxCategoryCoded>StandardRate</TaxCategoryCoded> <TaxTypeCoded>ValueAddedTax</TaxTypeCoded> <TaxPercent>.00</TaxPercent> <TaxableAmount>100.00</TaxableAmount> <TaxAmount>.00</TaxAmount> </Tax> <TotalValue> <MonetaryValue> <MonetaryAmount>200.00</MonetaryAmount> </MonetaryValue> </TotalValue> </PricingDetail> <DeliveryDetail> <ListOfScheduleLine> <ScheduleLine> <Quantity> <QuantityValue>2</QuantityValue> <UnitOfMeasurement> <UOMCoded>EA</UOMCoded> </UnitOfMeasurement> </Quantity> <RequestedDeliveryDate>20140904T00:00:00+01:00</RequestedDeliveryDate> </ScheduleLine> </ListOfScheduleLine> </DeliveryDetail> </ItemDetail> </ListOfItemDetail> </OrderDetail> <OrderSummary> <NumberOfLines>2</NumberOfLines> <TotalTax> <MonetaryValue> <MonetaryAmount>.00</MonetaryAmount> </MonetaryValue> </TotalTax> <TotalAmount> <MonetaryValue> <MonetaryAmount>220.00</MonetaryAmount> <Currency> <CurrencyCoded>NOK</CurrencyCoded> </Currency> </MonetaryValue> </TotalAmount> </OrderSummary> </Order> </SOAP-ENV:Body> </SOAP-ENV:Envelope> Hi guys, I'm using PHP Simple DOM, thanks to the good folk her I'm making progress. The html i'm parsing has a bunch of links in a li ul structure. I've managed to get the top layer of links extracted and I would like to have a count of the number of child nodes in the layer below the main links. Here is my code: $html = file_get_html('test/php/book.html'); if(!empty($html)){ $lis = $html->find('.chunklist', 0)->children() ; for ( $i = 0 ; $i < count($lis) ; $i++ ) { $parent_term = $lis[$i]->first_child()->innertext . ', ' ; $parent_node = $lis[$i]->children[0]->attr['href'] . '<br>' ; //echo count($parent_node->children()) ; this gives error Warning: count(): Parameter must be an array or an object that implements Countable echo $parent_term . $parent_node ; $parent_node = $const . $parent_node ; echo $parent_node ; $html2 = file_get_html($parent_node) ; $lis2 = $html2->find('.chunklist', 0)->children() ; } } I don't see anything in the manual regarding counting nodes, any idea how to go about this? Hi, I need to build my own xml validator and was wondering, what are some possible purposes of having multiple text nodes for a given parent node, I ask b/c while I was playing around with W3schools XML validator, I noticed it successfully validated the following: <?xml version="1.0" encoding="utf-8" ?> <note> <to>Joh</to> <from>Frank</from> <body>Hello world</body> Extra text node that is validated! </note> good day dear experts,
<?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.) Something is wrong an OSM Overpass API Endpoint // $Something is wrong = 'node ["addr:postcode"~"RM12"] (51.5557914,0.2118915,51.5673083,0.2369398)->.point; ( node (around.point:100000) ["amenity"~"school"]; way (around.point:100000) ["amenity"~"school"]; ); out;'; $context = stream_context_create(['http' => [ 'method' => 'POST', 'header' => ['Content-Type: application/x-www-form-urlencoded'], 'content' => 'data=' . urlencode($Something is wrong), ]]); # 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("Something is wrong returned %2\$d node(s) and took %1\$.5f seconds.\n\n", microtime(true) - $start, count($result->node)); // // 2.) Work with the XML Result // # get all school nodes with xpath $xpath = '//node[tag[@k = "amenity" and @v = "school"]]'; $schools = $result->xpath($xpath); printf("%d School(s) found:\n", count($schools)); foreach ($schools as $index => $school) { # Get the name of the school (if any), again with xpath list($name) = $school->xpath('tag[@k = "name"]/@v') + ['(unnamed)']; printf("#%02d: ID:%' -10s [%s,%s] %s\n", $index, $school['id'], $school['lat'], $school['lon'], $name); }
FATAL ERROR syntax error, unexpected 'is' (T_STRING) on line number 11
well at the moment i try to make up my mind what is going on here So 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 |