PHP - How To Fetch A Page With A Parser [live Demo]
good day, hello dear community!
i am currently ironing out a little parser-script. I have some bits - but now i need to have some improved spider-logic. See the target-url http://192.68.214.70/km/asps/schulsuche.asp?q=e&a=50 This page has got more than 6000 results! Well how do i get all the results? I tried out several things - but i dont helped. I allways got bad results. See i have good csv-data - but unfortunatley no spider logic... I need some bits to get there! How to get there!? I use the module LWP::simple and i need to have some improved arguments that i can use in order to get all the 6150 records #!/usr/bin/perl use warnings; use strict; use LWP::Simple; use HTML::TableExtract; use Text::CSV; my $html= get 'http://192.68.214.70/km/asps/schulsuche.asp?q=n&a=50'; $html =~ tr/r//d; # strip the carriage returns $html =~ s/ / /g; # expand the spaces my $te = new HTML::TableExtract(); $te->parse($html); my @cols = qw( rownum number name phone type website ); my @fields = qw( rownum number name street postal town phone fax type website ); my $csv = Text::CSV->new({ binary => 1 }); foreach my $ts ($te->table_states) { foreach my $row ($ts->rows) { trim leading/trailing whitespace from base fields s/^s+//, s/\s+$// for @$row; load the fields into the hash using a "hash slice" my %h; @h{@cols} = @$row; derive some fields from base fields, again using a hash slice @h{qw/name street postal town/} = split /n+/, $h{name}; @h{qw/phone fax/} = split /n+/, $h{phone}; trim leading/trailing whitespace from derived fields s/^s+//, s/\s+$// for @h{qw/name street postal town/}; $csv->combine(@h{@fields}); print $csv->string, "\n"; } } Well - with this i have a good csv-output:- but unfortunatley no spider logic. How to add the spider-logic here... !? well i need some help Love to hear from you Similar Tutorialsgood evening dear community! Howdy, at the moment i am debugging some lines of code... purpose: i want to process multiple webpages, kind of like a web spider/crawler might. I have some bits - but now i need to have some improved spider-logic. See the target-url http://192.68.214.70/km/asps/schulsuche.asp?q=e&a=50 This page has got more than 6000 results! Well how do i get all the results? I use the module LWP::simple and i need to have some improved arguments that i can use in order to get all the 6150 records Attempt: Here are the first 5 page URLs: http://192.68.214.70/km/asps/schulsuche.asp?q=e&a=50&s=0 http://192.68.214.70/km/asps/schulsuche.asp?q=e&a=50&s=50 http://192.68.214.70/km/asps/schulsuche.asp?q=e&a=50&s=100 http://192.68.214.70/km/asps/schulsuche.asp?q=e&a=50&s=150 http://192.68.214.70/km/asps/schulsuche.asp?q=e&a=50&s=200 We can see that the "s" attribute in the URL starts at 0 for page 1, then increases by 50 for each page there after. We can use this information to create a loop: #!/usr/bin/perl use warnings; use strict; use LWP::Simple; use HTML::TableExtract; use Text::CSV; my @cols = qw( rownum number name phone type website ); my @fields = qw( rownum number name street postal town phone fax type website ); my $i_first = "0"; my $i_last = "6100"; my $i_interval = "50"; for (my $i = $i_first; $i <= $i_last; $i += $i_interval) { my $html = get("http://192.68.214.70/km/asps/schulsuche.asp?q=e&a=50&s=$i"); $html =~ tr/r//d; # strip the carriage returns $html =~ s/ / /g; # expand the spaces my $te = new HTML::TableExtract(); $te->parse($html); my $csv = Text::CSV->new({ binary => 1 }); foreach my $ts ($te->table_states) { foreach my $row ($ts->rows) { #trim leading/trailing whitespace from base fields s/^s+//, s/\s+$// for @$row; #load the fields into the hash using a "hash slice" my %h; @h{@cols} = @$row; #derive some fields from base fields, again using a hash slice @h{qw/name street postal town/} = split /n+/, $h{name}; @h{qw/phone fax/} = split /n+/, $h{phone}; #trim leading/trailing whitespace from derived fields s/^s+//, s/\s+$// for @h{qw/name street postal town/}; $csv->combine(@h{@fields}); print $csv->string, "\n"; } } } i tested the code and get the following results: .- see below - the error message shown in the command line... btw: here the lines 57 and 58: #trim leading/trailing whitespace from derived fields s/^s+//, s/\s+$// for @h{qw/name street postal town/}; what do you think? Sta�e please Ot",,,Telefo,Fax,Schulat,Webseite Use of uninitialized value $_ in substitution (s///) at bavaria_all_guru.pl line 58. Use of uninitialized value $_ in substitution (s///) at bavaria_all_guru.pl line 58. Use of uninitialized value $_ in substitution (s///) at bavaria_all_guru.pl line 58. Use of uninitialized value $_ in substitution (s///) at bavaria_all_guru.pl line 58. "lfd. N.",Schul-numme,Schul,"ame Sta�e please Ot",,,Telefo,Fax,Schulat,Webseite Use of uninitialized value $_ in substitution (s///) at bavaria_all_guru.pl line 58. Use of uninitialized value $_ in substitution (s///) at bavaria_all_guru.pl line 58. Use of uninitialized value $_ in substitution (s///) at bavaria_all_guru.pl line 58. Use of uninitialized value $_ in substitution (s///) at bavaria_all_guru.pl line 58. "lfd. N.",Schul-numme,Schul,"ame Sta�e please Ot",,,Telefo,Fax,Schulat,Webseite Use of uninitialized value $_ in substitution (s///) at bavaria_all_guru.pl line 58. Use of uninitialized value $_ in substitution (s///) at bavaria_all_guru.pl line 58. Use of uninitialized value $_ in substitution (s///) at bavaria_all_guru.pl line 58. Use of uninitialized value $_ in substitution (s///) at bavaria_all_guru.pl line 58. "lfd. N.",Schul-numme,Schul,"ame Sta�e please Ot",,,Telefo,Fax,Schulat,Webseite Use of uninitialized value $_ in substitution (s///) at bavaria_all_guru.pl line 58. Use of uninitialized value $_ in substitution (s///) at bavaria_all_guru.pl line 58. Use of uninitialized value $_ in substitution (s///) at bavaria_all_guru.pl line 58. Use of uninitialized value $_ in substitution (s///) at bavaria_all_guru.pl line 58. "lfd. N.",Schul-numme,Schul,"ame hello dear Freaks
i am currently musing bout the portover of a python bs4 parser to php - working with the simplehtmldom-parser / pr the DOM-selectors... (see below). The project: for a list of meta-data of wordpress-plugins: - approx 50 plugins are of interest! but the challenge is: i want to fetch meta-data of all the existing plugins. What i subsequently want to filter out after the fetch is - those plugins that have the newest timestamp - that are updated (most) recently. It is all aobut acutality... https://wordpress.org/plugins/participants-database ....and so on and so forth.
https://wordpress.org/plugins/wp-job-manager we have the following set of meta-data for each wordpress-plugin: Version: 1.9.5.12 installations: 10,000+ WordPress Version: 5.0 or higher Tested up to: 5.4 PHP Version: 5.6 or higher Tags 3 Tags:databasemembersign-up formvolunteer Last updated: 19 hours ago
the project consits of two parts: the looping-part: (which seems to be pretty straightforward). the parser-part: where i have some issues - see below. I'm trying to loop through an array of URLs and scrape the data below from a list of wordpress-plugins. See my loop below- as a base i think it is good starting point to work from the following target-url:
plugins wordpress.org/plugins/browse/popular with 99 pages of content: cf ...
the Output of text_nodes: ['Version: 1.9.5.12', 'Active installations: 10,000+', 'Tested up to: 5.6 '] but if we want to fetch the data of all the wordpress-plugins and subesquently sort them to show the -let us say - latest 50 updated plugins. This would be a interesting task:
first of all we need to fetch the urls then we fetch the information and have to sort out the newest- the newest timestamp. Ie the plugin that updated most recently List the 50 newest items - that are the 50 plugins that are updated recently ..
we have the following set see here the Soup_ soup = BeautifulSoup(r.content, 'html.parser') target = [item.get_text(strip=True, separator=" ") for item in soup.find( "h3", class_="screen-reader-text").find_next("ul").findAll("li")[:8]] head = [soup.find("h1", class_="plugin-title").text] new = [x for x in target if x.startswith( ("V", "Las", "Ac", "W", "T", "P"))] return head + new with ThreadPoolExecutor(max_workers=50) as executor1: futures1 = [executor1.submit(parser, url) for url in allin] for future in futures1: print(future.result())
see the formal output Quote
background: https://stackoverflow.com/questions/61106309/fetching-multiple-urls-with-beautifulsoup-gathering-meta-data-in-wp-plugins Well - i guess that we c an do this with the simple DOM Parser - here the seclector reference. https://stackoverflow.com/questions/1390568/how-can-i-match-on-an-attribute-that-contains-a-certain-string
look forward to any hint and help.
have a great day Edited May 3, 2020 by dil_bertHi all, I have a strange issue going on. It may be server related, but I don't know what to look for. I have a .php page with a few Virtual Includes: Code: [Select] <?php virtual ("nav.shtml"); ?> ...throughout it. I have also a parser that is displaying XML data in a table form. The parser works with the standard: Code: [Select] <?php include ('parser.php'); ?> ...however, if I have the Virtual above the include, the parser doesn't work. Or at least it will not "find the file" however, the file is there and it works ABOVE the virtual, displaying it fine... For example, this works: Code: [Select] <?php include ('parser.php'); ?> <?php virtual ('file.shtml'); ?> This doesn't: Code: [Select] <?php virtual ('file.shtml'); ?> <?php include ('parser.php'); ?> Any thoughts? Hi there I'm a little bit of a newbie when it comes to PHP, and I have tried to find my answer on google and on other websites related to php development.
My question is what do I need to be researching / learning to automatically update a page with content.
For example, if I have a database field called breaking news and this text string is flashed at the bottom of the screen on a scrolling bar.
When the field changes value in MYSQL, I would like the page to automatically update the page without a need for a page refresh.
All I need is some advice on what I need to search for in order for me to learn the coding myself.
I'm thinking AJAX, but not too sure.
Thank you for reading.
How do you have a script, after getting the page, search for and as the result, post *part* of every link that ends like... &v=ANYTHING">Link text</a> and as the result, posting just ANYTHING">Link text<BR> I'm messing with... <?php $page = $_GET['page']; $user = $_GET['user']; $doc = new DOMDocument; $doc->load('http://m.youtube.com/profile?gl=US&client=mv-google&hl=en&user=$user&view=videos&p=$page'); $items = $doc->getElementsByTagName('a'); foreach($items as $value) { echo $value->nodeValue . "\n"; $attrs = $value->attributes; echo $attrs->getNamedItem('href')->nodeValue . "\n"; }; ?> but it get's way too much stuff. Get's data from every link on the page, and posts it as Page Text /watch?gl=US&client=mv-google&hl=en&v=XXXXX And I can't get $page = $_GET['page']; $user = $_GET['user']; to get the data from the URL. Is it possible to simply fetch from the server(mySql) and then dump it online through a PHP page? Is there some link that you can share? In one of my pages I have a section which contains a hidden line of text. When the user clicks a button the box containing the text will expand showing the line more clearly. I want this to happen live i.e. no page refresh/reload. I've seen such things done on other sites but my question is, is this done using a php function or is JavaScript required to achieve this? I assume that in order for any php functions to take place there must be a page refresh to reload the data/parameters/variables that are required? The site I'm referring to is this one:- http://www.vouchercodes.co.uk/featured-voucher-codes.html If you click on the "Get code and open site" buttons there for any of the vouchers the area expands live and the voucher is revealed however as I say there is no page refresh and it is done live. Is this effect done in JavaScript and not php or is there some way of using php alone to do something similar? Obviously including JScript in a site is more risky as if a user does not have it installed/activated then they may not be able to use such elements hence the reason I want to know how it is done. hello - dear phpfreaks,
i portet over a wordpress site to localhost. (an opensuse linux-box) all went nice and was very smooth to do so. after porting over the files and the db; i added the db-name and user-name etc. but nothing more. then i looked at the site http://localhost/mysite i saw the site - but only once - that is very very interesting. i read that i have to do more. Probably these changes - mentioned below are mandantory in order to avoid a blank page cf: https://managewp.com...#comment-148613 The two fields you need to edit are “siteurl” (highlighted above) and “home” (which you may need to navigate to the second page to find). Just click the “Edit” buttons next to each field, and replace the URL contained in “option_value” with “http://localhost/yourfoldername/”. That’s it! If you now navigate to “http://localhost/yourfoldername/”, your site should load up in all its glory. Please note that if you use custom permalinks, you will need to change them to default (in the WordPress > Settings > Permalinks screen) in order for internal links on your site to work. You can of course change the permalinks back to their custom form at any time. question: is this true? Do i need to make these changes to avoid a blank page!? This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=326913.0 Hey guys ;-) I got a client that asked me today to create him an MLM type website. The first part of my work would be to test if there system works so I need to run a full demo of the multilevel structure. The MLM structure works as follow: 1 person finds 2 members and they then find 2 more each and so on until we reach 100 level deep. If i got this right, At level 5 there will be 25 members At level 10 there will be 100 members At level 20 there will be 400 members At level 40 there will be 1.600 members At level 100 there will be 10.000 members So at the end of the demo there should be 10k members inserted into the table The table looks like this: id, parent, level, under Parent is the ID of the guy that recruited him, level is the level that guy is at (level 1, 2 , 3, 4 or 5) and under is the number of people under him. I need to run a script that will insert all the data into that table so that we can run some test on the liability of the project so we can set the rates right. At first I thought it would be a piece of cake ... but when I started I found out very fast that populating the MLM network 5 level deep is gona be tricky ... my first attempt gave me a result that looks like this: Code: [Select] |0| |1|2| |x|x|3|4| x|x|x|x|x|x|5|6| As you can see the script only grab the last id then adds 2 new members then uses the last one as the parent and starts over ... So my script is useless and I did not figer out how to do everything in 1 step ... Any help would be appreciated. This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=317771.0 Hi there, I am working on a PHP Ecommerce website. We have multiple Suppliers on the website listing their products. Now when a customer buys multiple products belonging to multiple suppliers, the payment has to go to those different respective suppliers through a single Paypal checkout. I have come to know that there is a way of doing is using Paypal Parallel payments method. Its he http://feefighters.com/blog/paypal-announces-adaptive-payments-parallel-payments-and-chained-payments-functionality-via-api/ Anybody here has a working demo of how it works. Kindly reply. Thank you! All comments feedback are always welcomed! Hello everyone, Let me start by saying that this is my first post on this forum and that I am quite a noob when it comes to scripting. With that said, here is my problem: I am trying to edit a getID3 demo file properly to retrieve metadata from mp4 files. The code below belongs from the demo file. <?php require_once('../getid3/getid3.php'); $getID3 = new getID3; $DirectoryToScan = '../container'; $dir = opendir($DirectoryToScan); echo '<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="3">'; echo '<TR><TH>Filename</TH><TH>Artist</TH><TH>Title</TH><TH>Bitrate</TH><TH>Playtime</TH></TR>'; while (($file = readdir($dir)) !== false) { $FullFileName = realpath($DirectoryToScan.'/'.$file); if (is_file($FullFileName)) { set_time_limit(30); $ThisFileInfo = $getID3->analyze($FullFileName); getid3_lib::CopyTagsToComments($ThisFileInfo); echo '<TR>'; echo '<TD>'.$ThisFileInfo['filenamepath'].'</TD>'; echo '<TD>'.(!empty($ThisFileInfo['comments_html']['artist']) ? implode('<BR>', $ThisFileInfo['comments_html']['artist']) : ' ').'</TD>'; echo '<TD>'.(!empty($ThisFileInfo['comments_html']['title']) ? implode('<BR>', $ThisFileInfo['comments_html']['title']) : ' ').'</TD>'; echo '<TD ALIGN="RIGHT">'.(!empty($ThisFileInfo['audio']['bitrate']) ? round($ThisFileInfo['audio']['bitrate'] / 1000).' kbps' : ' ').'</TD>'; echo '<TD ALIGN="RIGHT">'.(!empty($ThisFileInfo['playtime_string']) ? $ThisFileInfo['playtime_string'] : ' ').'</TD>'; echo '</TR>'; } } ?> I have added 2 test files in 'container' for testing only. See this image for the result I am getting. As you can see the code isn't retrieving any data at all. Can anyone help me out with this? Thanks in advance, Melissa hello dear all, good day dear php-freaks,
i want to rssify content from another website into my wordpress-page: see the source: https://europa.eu/youth/volunteering/project_en well - is it possible to do this? of course - i have to ask bout the permission at the site of source. but the technical site is also interesting :do you think that this is doable!? note: i only am interested in the summary of the data - that is only a little piece of text.
I need a little bit of help. I have a problem in which I need to read a file using fopen then open another file and look for a match and then take the information from both and enter it in a database then loop like 1000-2000 times. EG: Code: [Select] 8;"zip";"File1.zip";"post-36-10839578260.ibf";"318";"7129";"8cc3bac5f531206b9ca0414d08430b1e";"3485" 27;"zip";"File2.zip";"post-40-10840088850.ibf";"222";"7162";"6af0e0d5798485656a2fd78d75a86e6d";"60984" and find the matching text in another csv file. Also, there is like 1000+ lines. The easy think I could think of is to parse the information and put it into a table and search the table.. hi, i have this xml <m time="2012-03-09T11:14:20+00:00" timestamp="1331291660"> <ma id="1219457" xsid="0"> <time>2012-03-09T19:30:00+00:00</time> <gru id="8388">Nacional</gru> <ht id="2325">Teste</ht> <at id="8919">Teste2</at> <results /> <mar did="6" name="Under"> <ofr id="95690814" n="2" ot="0" last_updated="2012-03-09T11:13:35+00:00" flags="1" bmoid="1000095485"> <ors i="0" time="2012-03-08T18:59:22+00:00" starting_time="2012-03-09T19:30:00+00:00"> <a1>4</a1> <a2>3.5</a2> <a3>4</a3> <a4>2</a4> <a5>8</a5> </ors> </ofr> </mar> </ma> </m> and this code: $DOMDocument = new DOMDocument( '1.0' , 'utf-8' ); $DOMDocument->preserveWhiteSpace = false; $DOMDocument->loadXML( $xml ); foreach ( $DOMDocument->getElementsByTagName( '*' ) as $Nodes ) { foreach ( $Nodes->getElementsByTagName( '*' ) as $Node ) { $Data[ $Node->parentNode->nodeName ][ $Node->nodeName ] = $Node->nodeValue; } with this code i can load the value of the a1 and a2 etc but i need load the name of the mar ( Under ) and the did. how can i do this? thanks I am trying to parse a XML file using SimpleXML, but I can't figure out how to display <Category> name and each <feature> Here's a example of the XML file. <Vehicle> <Description>To set an appointment callor email </Description> <Features> <Category Name="Comfort"> <Feature>Front Air Conditioning</Feature> <Feature>Front Air Conditioning Zones: Single</Feature> <Feature>Front Air Conditioning: Climate Control</Feature> </Category> </Features> </Vehicle> Code: [Select] <?php $dom = new DOMDocument(); $dom->loadHTMLFile('http://en.wikipedia.org/wiki/Liverpool_F.C.'); $domxpath = new DOMXPath($dom); foreach ($domxpath->query('//span[@id="Players"]/../following-sibling::table[1]//span[@class="fn"]') as $a) {echo " <p>$a->textContent</p> "; }; ?> Hello, how can I parse an XML that includes all of the $a->textContent with a tag like <player></player>? Hi All. I was working on this class for the last .. 2 hours or so. I was just wondering, if any of you could see anything immediatly wrong with it. I haven't really had chance to test it. If it does work. Help yourselves to it. <?php /* Made By Richard Clifford for the use and redistribution under the GPL 2 license. If you wish to use this class, please leave my name and this comment in here. */ /* Usage Example: $this->objXML->loadXMLDoc('Document.xml'); #Must start with This $this->objXML->getChildren(); $this->objXML->getChildrenByNode('NodeName'); $this->objXML->asXML(); $this->objXML->addAttribute('attrName','attrValue'); $this->objXML->addChild('ParentName','childName'); $this->objXML->getAttributesByNode('Attr'); $this->objXML->xmlToXPath(); $this->objXML->countChildren('parentNode'); */ class XML{ function __construct(){ //Calls the loadXMLDoc func $this->loadXMLDoc($docName); } /** @Brief Loads the XML doc to read from @Param docName The Name of the XML document @Param element The SimpleXMLElement, Default = null @Since Version 1. Dev @Return blOut Boolean */ public function loadXMLDoc($docName, $element = null){ //Set the Return value $blOut = false; //Load the XML Document $XML = simplexml_load_file($docName); //Call the SimpleXMLElement $SXE = new SimpleXMLElement($element); //Checks to make sure the file is loaded and the SimpleXMLElement has been called if( ($XML == TRUE) && ($SXE == TRUE)){ $blOut = true; }else{ die('Sorry, Something Went Wrong'); } //Return the Variable return $blOut; } /** @Brief Gets an XML Child Attribute @Since Version 1. Dev @Returns $strOut String from the Child */ public function getChildren(){ if(!$this->loadXMLDoc() ){ die('Couldn\'t Load XML Document');} $strOut = NULL; //Loads the XML Document $XML = $this->loadXMLDoc(); //Gets all of the Children in the Document $xmlChildren = $XML->children(); //Loops through the children to give each Child and its value. foreach($xmlChildren as $child){ $strOut = $child->getName() . ':' . $child . '<br />'; } return $strOut; } /** @Brief Return a well-formed XML string based on SimpleXML element @Since Version 1. Dev @Returns $strOut The Well Formed XML string */ public function asXML(){ if(!$this->loadXMLDoc() ){ die('Couldn\'t Load XML Document');} $strOut = NULL; //Loads XML DOC $strToXML = $this->loadXMLDoc(); //Calls the Element $SXE = new SimpleXMLElement($strToXML); if(!$SXE){ die('Oops, something went wrong'); }else{ //Set the Return Value as the XML $strOut = $xml->asXML(); } return $strOut; } /** @Brief Adds an attribute to the SimpleXML element @Since Version 1. Dev @Returns $blOut Boolean */ public function addAttribute($element, $attrName, $attrValue){ if(!$this->loadXMLDoc() ){ die('Couldn\'t Load XML Document');} $blOut = false; //loads the XML Doc and sets the SXE (SimpleXMLElement) $addAttr = $this->loadXMLDoc($this->docName, $element); $addNewAttr = $addAttr->addAttribute($attrName, $attrValue, $namespace = null); if(!$addNewAttr){ die('Sorry We could not add the attribute at this time.'); }else{ $blOut = true; } return $blOut; } /** @Brief Adds a child element to the XML node @Since Version 1. Dev @Returns $blOut Boolean */ public function addChild($childName, $childValue, $namespace = null){ if(!$this->loadXMLDoc() ){ die('Couldn\'t Load XML Document');} $blOut = false; //Loads the XML Doc $addChild = $this->loadXMLDoc(); //Adds a new child to the document $addNewChild = $addChild->addChild($childName, $childValue, $namespace); if(!$addNewChild){ die('Sorry, I couldn\'t addChild at this Time'); }else{ $blOut = true; } return $blOut; } /** @Brief Finds children of given node @Since Version 1. Dev @Param $nodeName The Name of the Node to retrieve Children @Param $prefix If is_prefix is TRUE, ns will be regarded as a prefix. If FALSE, ns will be regarded as a namespace URL. @Returns $arrOut Multi-Dimensional Array */ public function getChildrenByNode($nodeName, $prefix = true){ if(!$this->loadXMLDoc() ){ die('Couldn\'t Load XML Document');} $arrOut = array(); $xml = $this->loadXMLDoc(); $getChildren = $xml->children($nodeName); foreach($getChildren as $child){ $arrOut['child_name'] = array($child); } return $arrOut; } /** @Brief Gets an array of attributes from a node name @Since Version 1. Dev @Param $nodeName The name of a Node to get a */ public function getAttributesByNode($nodeName){ if(!$this->loadXMLDoc() ){ die('Couldn\'t Load XML Document');} $arrOut = array(); //Loads the XML Document $loadXml = $this->loadXMLDoc(); //Gets the XML code $xml = $loadXML->asXML(); //Loads the XML into a string $xmlString = simplexml_load_string($xml); //For each attribute in the XML Code string set as $attr=>$value foreach($xmlString->$nodeName->attributes() as $attr=>$value){ $arrOut = array($attr=>$value); } return $arrOut; } /** @COMPLETE AT A LATER DATE @NEED TO LOOKUP */ public function xmlToXPath(){ } /** @Brief Counts how many children are in a node @Param $nodeName The name of the node to query @Returns $strOut Counts the amount of children in a node, and adds it to a string. */ public function countChildren($nodeName, $return = 'int'){ if(!$this->loadXMLDoc() ){ die('Couldn\'t Load XML Document');} //Switch the $return as the user may want an integer or a string returned. switch($return){ case 'str': //if $strOut = NULL fails then user $strOut = ''; $strOut = NULL; //Load the XML Document $xml = $this->loadXmlDoc(); //Get the Children $xmlNode = $this->getChildrenByNode($nodeName); //Set a counter $counted = 0; //Forevery child in every node foreach($xmlNode as $child){ //add one to the counter $counted++; //return a string $strOut = sprintf('The %s has %s children',$xmlNode, $child); } return $strOut; break; case 'int': $intOut = 0; $xml = $this->loadXmlDoc(); $xmlNode = $this->getChildrenByNode($nodeName); $counted = 0; foreach($xmlNode as $child){ $counted++; } //Return the counter(int) (int) $intOut = $counted; return $intOut; break; } return $return; } } ?> Best Regards, Mantyy |