Jump to content

Search the Community

Showing results for tags 'dom'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 11 results

  1. Hello, I have a sample shop that generates a receipt on products purchased. When a user checks out it generates a receipt as a pdf file using dompdf. If i select a few products and generate a pdf file its ok it shows the products and total price, however if i choose lots of products, too many to fit on one page then when i generate a pdf it only show the first page the rest of the products and the total price are not displayed on page 2 ? Here is the bit of the code that generates the pdf sorry i am not very experienced in this stuff i am trying to learn ! $options = new Dompdf\Options(); $options->set('isRemoteEnabled', true); $dompdf = new Dompdf\Dompdf($options); $dompdf->loadHtml($html); $dompdf->render(); $output = $dompdf->output(); $info = file_put_contents("../../files/" . $filepath . $filename, $output); return array($filename,$filepath); any advice please.
  2. For an exercise I have to crawl some eBay pages and extract product information and metadata. I am bloody new to PHP, this is my first try. I am using the Simple HTML DOM parser class from here as a great start: http://simplehtmldom.sourceforge.net/ I can open a single product collection just fine: $html = file_get_html ( 'http://www.ebay.com/cln/linda*s***stuff/Red-Carpet-Ready-Grammy-Inspired-Style/76271969013' ); but to get all possible collections I'd need to URL like this: $html = file_get_html ( 'http://www.ebay.com/cln#{"category":{"id":1,"text":"Collectibles"}}' ); This doesn't work. For some reason the wrong page is loaded. It's always http://www.ebay.com/cln# Could be a problem with the active eBay pages or something else. I can't figure it out. Doesn anyone have a better idea how to solve this problem? I am running out of ideas here.. Any tips would be highly appreciated! Cheers, End Full test code below: <?php include_once 'simple_html_dom.php'; /* $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, 'http://www.ebay.com/cln#{"category":{"id":20091}}'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10); $str = curl_exec($curl); curl_close($curl); $html = str_get_html($str); */ $html = file_get_html ( 'http://www.ebay.com/cln/linda*s***stuff/Red-Carpet-Ready-Grammy-Inspired-Style/76271969013' ); // Looking for the big class and scraping image, title and other metadata foreach ( $html->find ( 'div[class="thumb big bigL"]' ) as $bigclass ) { foreach ( $bigclass->find ( 'img' ) as $bigimage ) { } ; foreach ( $bigclass->find ( 'div[class=itemPrice]' ) as $bigprice ) { } ; foreach ( $bigclass->find ( 'div[class=soldBy]' ) as $bigseller ) { } ; echo $bigimage->alt . "<br/>" . $bigimage . "<br />" . $bigprice . "<br/>" . $bigseller . "<br/><br/>"; } ; foreach ( $html->find ( 'div[class="thumb big bigR"]' ) as $bigclass1 ) { foreach ( $bigclass1->find ( 'img' ) as $bigimage ) { } ; foreach ( $bigclass1->find ( 'div[class=itemPrice]' ) as $bigprice ) { } ; foreach ( $bigclass1->find ( 'div[class=soldBy]' ) as $bigseller ) { } ; echo $bigimage->alt . "<br/>" . $bigimage . "<br />" . $bigprice . "<br/>" . $bigseller . "<br/><br/>"; } ; // Looking for the smaller class and scraping image, title and other metadata foreach ( $html->find ( 'div[class="thumb small"]' ) as $smallclass ) { foreach ( $smallclass->find ( 'img' ) as $smallimage ) { } ; foreach ( $smallclass->find ( 'div[class=itemPrice]' ) as $smallprice ) { } ; foreach ( $smallclass->find ( 'div[class=soldBy]' ) as $smallseller ) { } ; echo $smallimage->alt . "<br/>" . $smallimage . "<br />" . $smallprice . "<br/>" . $smallseller . "<br/><br/>"; } ?> test.php simple_html_dom.zip
  3. I am only a few months into PHP and don't grasp all the things that i guess the "expert" programmers do, so for that i'm sorry... i'm working on it. I need help with what code would accomplish what i need below, I have had only partial success but am now stuck. I have used CURL to post to a remote site form and return the results, the returned results is the full raw HTML of that forms results page. There is only 1 table of data i need from the entire page and the only unique identifier of the table is a unique CLASS attribute. I have been able, through trial and error to get the initial stage of assigning the HTML response to a PHP DOM object and identify the needed table by its class assignment using an example found on the net. But: 1.) I really am having a hard time understand the whole DOM object models and manipulation. 2.) The code below, returns the TABLE i need, but all HTML is stripped form it, thus i just get one long running line of text. I need that table and its content, html tags and all assigned to a variable. Please help. Example: ^^^^^^ Lots of misc HTML code above ^^^^^^ <table class="magicname" height=100 width=100> <tr> <td> <p>whatever content is in here </p> </td> </tr> <tr> <td> <p>whatever content is in here </p> </td> </tr> </table> vvvvv Lots of misc HTML code below vvvv My Current code: $classname = 'maintbl'; $dom = new DOMDocument; $dom->loadHTML($server_output); $xpath = new DOMXPath($dom); $results = $xpath->query("//*[@class=" . $classname . "]"); foreach($results as $node) { echo "{$node->nodeName} - {$node->nodeValue}<br>"; // or you can just print out the the XML: // $dom->saveXML($node);
  4. Hi can someone help me out as i'm new to php. I have a grabber built in to my script that gets info from other sites for example. This part is from the site that my grabber gets the info from. <div class="txt-block"> <h4 class="inline">Runtime:</h4> <time itemprop="duration" datetime="PT103M">103 min</time> </div> And this is how my grabber gets this info from the site. $times = $dom->getElementsByTagName('time'); for($i=0; $i<$times->length; $i++){ $itemprop = $times->item($i)->getAttribute("itemprop"); if ($itemprop == "duration"){ if ($times->item($i)->textContent!='-'){ $res['duration'] = $times->item($i)->textContent; } } } Now what i'm stuck on is what would the code be to get the date published from the site. <span class="nobr"> <a href="/title/tt0099785/releaseinfo?ref_=tt_ov_inf " title="See all release dates"> 16 November 1990 <meta itemprop="datePublished" content="1990-11-16"> (USA) </a> </span> Would it be something like this. $meta = $dom->getElementsByTagName('meta'); for($i=0; $i<$meta->length; $i++){ $itemprop = $meta->item($i)->getAttribute("itemprop"); if ($itemprop == "datePublished"){ if ($meta->item($i)->textContent!='-'){ $res['datePublished'] = $meta->item($i)->textContent; } } } Could someone please help as i don't have a clue about writing php.
  5. I would like to get Type, Id and Height values in database table. It is not working. There is no error message. XML File: <?xml version="1.0" encoding="utf-8"?> <Physical> <Catalog> <EquipmentSpec> <Reference>030_17</Reference> <Type>Duplexeur</Type> <Characteristic><CharacteristicName>Tilt</CharacteristicName> <CharacteristicValue>0</CharacteristicValue></Characteristic> </EquipmentSpec> <EquipmentSpec> <Reference>030_19</Reference> <Type>Node</Type> <Characteristic><CharacteristicName>Tilt</CharacteristicName> <CharacteristicValue>0</CharacteristicValue></Characteristic> </EquipmentSpec> </Catalog> <Installed> <Equipment> <Id>26</Id><Reference>MAT_4</Reference> <Characteristic><CharacteristicName>Height</CharacteristicName><CharacteristicValue>160</CharacteristicValue></Characteristic> </Equipment> <Equipment> <Id>27</Id><Reference>MAT_6890</Reference> <Characteristic><CharacteristicName>Height</CharacteristicName><CharacteristicValue>180</CharacteristicValue></Characteristic> </Equipment> </Installed> </Physical> CODE: foreach ($xml->xpath('Physical') as $spec) { foreach ($spec->xpath('//EquipmentSpec') as $sub) { $Type = $sub->Type; } foreach ($spec->xpath('//Equipment') as $eq) { $Id = $eq->Id; foreach ($eq->Characteristic as $c) { if ($c->CharacteristicName == 'Height') { $Height = $c->CharacteristicValue; } } } $sql = "INSERT INTO machines (`Type`,`Id`,`Height`) VALUES ('".$Type."','".$Id."','".$Height."')"; $req = new requete($site->db, $sql); echo $sql; }
  6. Hello, I'm working on a project where I would like to load the contents of one webpage (that I'm not hosting) into a webpage that I am hosting with the ability to access the DOM of the non-hosted page. What I would like to do is load a different page (GUI for an internal system) within my own webpage, and then be able to select elements within the GUI using jQuery and add CSS styling to them. I figured iframes would be the easiest way to handle this, but then learned about the Same Origin Policy, which denies access to the DOM of a non-hosted page in the iframe. So then I tried using a PHP Include statement to load the GUI within my page. I've run in to 2 roadblocks with this method: The first is that when I tested this method using google.com as the included site, as soon as you click on a link, it takes you outside of my site and on to google. I'll definitely need the ability for users to click around within the GUI but still remain within my site. The 2nd issue I'm having is simply including the GUI since it's web address is an IP Address. I keep getting the following error: Warning: include() [function.include]: Failed opening 'http://192.168.1.xx' for inclusion (include_path='.:/usr/local/lib/php') in /home1/public_html/example.com/example.php. If anyone has any advice as to whether it's possible to acheive this, I'd love to hear some feedback. Maybe PHP isn't even the answer. Maybe I'm going about this all wrong. I'm definitely open to any suggestions at this point! Thanks for reading, DJS
  7. I'm trying to pick out items from an XML file by their titles using Xpath in DOM, but because some have apostrophes, and others have quotes, it doesn't work. I've tried replacing the apostrophes using this $query1 = 'channel/item[title='.$p.']/title'; but it only works for the apostrophes, not the quotes. Any advice on how to do this? <?php $q = $_GET["q"]; $q = explode('|^', $q); $counts = count($q); unset($q[$counts-1]); $p = stripslashes($q); $q = stripslashes($p); $dom = new DOMDocument; $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->Load("../$userid.xml"); $xpath = new DOMXPath($dom); foreach ($q as $r) { $p = preg_replace("/'/","",$r); $query1 = "channel/item[title="'.$p.']/title"; $query2 = "channel/item[title="'.$p.']/url"; $query3 = "channel/item[title="'.$p.']"; $entries = $xpath->query($query1); $entries2 = $xpath->query($query2); $entries3 = $xpath->query($query3); foreach ($entries as $entry) { foreach ($entries2 as $entry2) { foreach ($entries3 as $entry3) { $oldchapter = $entry->parentNode->removeChild($entry); $oldchapter2 = $entry2->parentNode->removeChild($entry2); $oldchapter3 = $entry3->parentNode->removeChild($entry3); $dom->preserveWhiteSpace = false; } } } } $dom->formatOutput = true; $dom->save("../$userid.xml") ?> Basically, my code extracts titles from a URL, separated by "|^" (For example title1|^title2|^title3|^). Because the "|^" is appended to the end of each title, I have to remove the empty value from the array. Then, because the titles with apostrophes come in like "Title\\'s", I have to strip slashes twice to get rid of them. Then I load a new DOMdocument, and find the titles from the URL in my existing XML document. Then I want the code to remove the whole items (titles, urls and the item itself) which have the same titles as the ones in the URL, and then save the document.
  8. Basically, I am writing a script in PHP, which can take YouTube videos from playlists, items from RSS feeds and podcasts, and individual YouTube videos and files, and places them into an XML document, so they can browsed and kept in one place. I also have a script which removes these items, if the user wants. The problem I'm facing is with characters. Because I can't control what the user will name their videos/files, or how they're named in the feed, the titles could have quotes, brackets, ampersands, hashes etc, which causes problems when they're being removed and Because I'm using Xpath (which can be temperamental at the best of times) in the remove script, any items with titles with these characters won't get removed. Here's my remove code: <?php $q = $_GET["q"]; $q = stripslashes($q); $q = explode('|^', $q); $counts = count($q); unset($q[$counts-1]); $dom = new DOMDocument; $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->Load("../$userid.xml"); $xpath = new DOMXPath($dom); foreach ($q as $r) { $r = preg_replace("|&|", '&', $r); $r = preg_replace('|"|', '"', $r); $query1 = 'channel/item[title='.$r.']/title'; $query2 = 'channel/item[title='.$r.']/media:content'; $query3 = 'channel/item[title='.$r.']'; $entries = $xpath->query($query1); $entries2 = $xpath->query($query2); $entries3 = $xpath->query($query3); foreach ($entries as $entry) { foreach ($entries2 as $entry2) { foreach ($entries3 as $entry3) { $oldchapter = $entry->parentNode->removeChild($entry); $oldchapter2 = $entry2->parentNode->removeChild($entry2); $oldchapter3 = $entry3->parentNode->removeChild($entry3); $dom->preserveWhiteSpace = false; } } } } $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->save("../$userid.xml") ?> How it works is when the user selects the items they want to remove, using a select box, the selections are put into the URL. My code extracts the titles from the URL, separated by "|^" (For example title1|^title2|^title3|^). Because the "|^" is appended to the end of each title, I have to remove the empty value from the array. Then I load a new DOMdocument, and find the titles from the URL in my existing XML document. Then I want the code to remove the whole items (titles, urls and the item itself) which have the same titles as the ones in the URL, and then save the document, but because some of the titles could have &, ", * or #, they don't get removed. Is there a way that I can maybe screen, and change the characters to get it to work (I tried this with "preg_replace", but it didn't work), or even change them before they're saved to the XML in the first place? Any advice?
  9. I'm trying to pick out items from an XML file by their titles using Xpath in DOM, but because some have apostrophes, it doesn't work. I've tried replacing the apostrophes using this $query1 = "channel/item[title=$p]/title"; but even that doesn't work. Any advice on how to do this, or alternatives for how to extract elements by their titles in DOM? Here's my code: <?php $q = $_GET["q"]; $q = explode('|^', $q); $counts = count($q); unset($q[$counts-1]); $p = stripslashes($q); $q = stripslashes($p); $dom = new DOMDocument; $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->Load("../$userid.xml"); $xpath = new DOMXPath($dom); foreach ($q as $r) { $p = preg_replace("/'/","",$r); $query1 = "channel/item[title=$p]/title"; $query2 = "channel/item[title=$p]/url"; $query3 = "channel/item[title=$p]"; $entries = $xpath->query($query1); $entries2 = $xpath->query($query2); $entries3 = $xpath->query($query3); foreach ($entries as $entry) { foreach ($entries2 as $entry2) { foreach ($entries3 as $entry3) { $oldchapter = $entry->parentNode->removeChild($entry); $oldchapter2 = $entry2->parentNode->removeChild($entry2); $oldchapter3 = $entry3->parentNode->removeChild($entry3); $dom->preserveWhiteSpace = false; } } } } $dom->formatOutput = true; $dom->save("../$userid.xml") ?> Basically, my code extracts titles from a URL, separated by "|^" (For example title1|^title2|^title3|^). Because the "|^" is appended to the end of each title, I have to remove the empty value from the array. Then, because the titles with apostrophes come in like "Title\\'s", I have to strip slashes twice to get rid of them. Then I load a new DOMdocument, and find the titles from the URL in my existing XML document. Then I want the code to remove the whole items (titles, urls and the item itself) which have the same titles as the ones in the URL, and then save the document.
  10. Hello. This is my first post, and i hope i post this topic in the right area. So, i have a script which gets content from another site using $dom and i want to manipulate the exported links. I have in the script the line " $td->getElementsByTagName('a')->item(0)->setAttribute('href', 'http://google.com'); " which edit the links from col 2, and i want to make the same with the links from col 10. And in col 10 i have some problems showing the results just like on the website. Please help. Thank you ! <?php $content = file_get_contents("http://www.soccerway.com/national/germany/bundesliga/20122013/regular-season/"); $content = '<?xml encoding="UTF-8">' . $content; libxml_use_internal_errors(true); $dom = new DomDocument(); $dom->loadHTML($content); libxml_clear_errors(); $xpath = new DomXPath($dom); $tabele = $xpath->query('//table[contains(concat(" ", normalize-space(@class), " "), "leaguetable")]'); $tabel = $tabele->item(0); $trs = $tabele->item(0)->getElementsByTagName('tr'); print '<table>'; foreach($trs as $rowIndex => $tr){ $tds = $tr->getElementsByTagName('td'); if($rowIndex > 18) continue; print '<tr>'; foreach($tds as $colIndex => $td){ if($colIndex == 2) $td->getElementsByTagName('a')->item(0)->setAttribute('href', 'http://google.com'); if($colIndex > 11) continue; // salveaza HTML printf('<td> %s </td>', $dom->saveXML($td)); } print '</tr>'; } print '</table>'; ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.