Simple HTMLDom - i'm confused - php

I would like to show all files i share on my owncloud instance on my "normal" homepage.
The URL of my owncloudserver is: https://cloud.berndklaus.at/public.php?service=files&t=187e4767cb0421c7505cc3ceee450289
From there i would like to show the Filename, the Size and the Last modified Date on my Hompage. I'm actually able to display the Filename and the Last modified name but not the Filesize.
I tried several thinks, but nothing worked, could u help me out?
Sorry for my (bad) english!! :)
Code to display:
$html = file_get_html('https://cloud.berndklaus.at/public.php?service=files&t=187e4767cb0421c7505cc3ceee450289');
//find the table
$td = $html->find('td');
//find all links inside the table
foreach($td as $tds)
{
// Output the Links
//echo $tds;
echo $tds->find('a',0) . "-";
echo $tds->find('span[class=modified]', 0)->plaintext;
}
?>

Here's clean way to retrieve the wanted informations... The idea is to retrieve all rows then extract the useful data inside a loop :
$url = "https://cloud.berndklaus.at/public.php?service=files&t=187e4767cb0421c7505cc3ceee450289";
//Create a DOM object
$html = new simple_html_dom();
// Load HTML from a string
$html->load_file($url);
// Find all rows (files)
$files = $html->find('#fileList tr[data-id]');
// loop through all found files, extract and print the content
foreach($files as $file) {
$fileName = $file->find('span.nametext', 0)->plaintext;
$fileSize = $file->find('td.filesize', 0)->plaintext;
$modDate = $file->find('span.modified', 0)->title;
echo $fileName . " # " . $fileSize . " # " . $modDate . "<br>";
}
// Clear DOM object
$html->clear();
unset($html);
OUTPUT
Christi und Bernd - XMAS.JPG # 363.1 kB # December 29, 2013 10:59
Working DEMO

Related

How to integrate a link to parse in PHP Simple XML

I need to download all photos about estates from an XML to save on the server. Every estate child in the XMl has a general section with all information and then a node called Foto (estate's photos) and another one for plans (Planimetria). The link of every image is structured as is:
<Link>http://www.site.it/ImageView.ashx?id=[photoID]&reduce=1438[can be set as I want es: 1000, 960, 1080]</Link>
I need to call it inside the $url_photo and $url_plan so I can read the photoID from XML and set resolution (1438,1000,960) with a global variable.
This is my code:
<?php
$xml = simplexml_load_file("Schede.xml"); // your xml
$path = '/mnt/c/Users/Giuseppe/Desktop/FotoTest/';
$i = 1;
$resolution = '1000';
// Estate Image
foreach($xml->CR03_SCHEDE as $estate){
//if((string) $estate['ELIMINATO'] = "NO"){
echo "\nEstate n $i Images\n";
foreach($estate->Foto->CR04_SCHEDE_FOTO as $photo){
$url_photo = (string) $photo->Link;
$filename_photo = basename($photo->CR04_FILENAME); // get the filename
if(file_exists($path . $filename_photo)) {
echo "file $filename_photo already exists \n";
}
else {
$img_photo = file_get_contents($url_photo); // get the image from the url
file_put_contents($path . $filename_photo, $img_photo); // create a file and feed the image
echo "file $filename_photo created \n";
}
}
// Plans
echo "\nEstate n $i plans\n";
foreach($estate->Planimetria->CR04_SCHEDE_FOTO as $plan) {
$url_plan = (string) $plan->'http: // www.site.it/ImageView.ashx?id=' . $plan->ID . '&reduce=' . $resolution; //$plan->Link;
$filename_plan = basename($plan->CR04_FILENAME);
if(file_exists($path . $filename_plan)) {
echo "file planimetry $filename_plan already exists \n";
}
else {
$img_plan = file_get_contents($url_plan); // get the image from the url
file_put_contents($path . $filename_plan, $img_plan); // create a file and feed the image
echo "file planimetry $filename_plan created \n";
}
}
$i++;
/*}
else{
echo "$estate->attributes(Riferimento)"."Deleted\n";
}*/
}
?>
I also have a problem with the first if commented:
if((string) $estate['ELIMINATO'] = "NO")...
Eliminato is an attribute of CR03_SCHEDE but the script won't read it and in any case go inside the if.
The complete XML has about 70/80 properties and the foreach works well to download all images, but I need that it should download the only one that has that attribute equals to NO
This is the example of XML (only one estate): link
Thanks to all
This is a classic mistake:
if((string) $estate['ELIMINATO'] = "NO")
You used the assignment operator instead of the comparison operator. Please use this exact form:
if ('NO' == (string)$estate['ELIMINATO'])

Writing and Updating ~8K-10K Iterations of URLs Strings on a Text File (PHP, Performance, CRON)

Problem
I have tried to write an only list-urls sitemap on a txt file. A file is generated daily and can be updated.
Trial
generateSitemap is part of a large class UpdateStocks which gets an input string and writes a URL for that input iterating about ~8-10K. Inputs are being generated using data from an API right before going to generateSitemap.
Performance
Would you be so kind and help me to possibly make it faster, simpler or more efficient? There is a small bug in generateSitemap that I could not find out, when it updates the file, sometimes, there is an extra newline \n in the txt file.
Pseudocode that calls the generateSitemap
{pseudocode} for i=1 to 8000;
generate input[i]; // for example: 'aapl-apple-technology-nasdaq-us-8f4c'
UpdateStocks::generateSitemap(input[i]);
{/pseudocode} endfor;
Class Constant
const DIR_URL_KEYWORD_1 = "equity";
const DIR_URL_KEYWORD_2 = "equilibrium-estimation";
const DOMAIN = "domain.org";
const EXTENSION_MD = ".md";
const EXTENSION_TXT = ".txt";
const NEW_LINE = "\n";
const PROTOCOL = "https://";
const SITEMAP_PREFIX = "/sitemap-";
const SLASH = "/";
generateSitemap
/**
*
* #return a large string in a txt file including all urls for a daily sitemap
*/
public static function generateSitemap($lurl){
$dir=__DIR__ . self::DIR_FRONT_PUBLIC_HTML;
// url
$sm=sprintf('%s%s%s',
self::PROTOCOL.self::DOMAIN.self::SLASH.self::DIR_URL_KEYWORD_1.self::SLASH.self::DIR_URL_KEYWORD_2.self::SLASH,
$lurl,
self::NEW_LINE
);
$dt=new \DateTime('now');
$dt=$dt->format('Y-m-d'); // today
$fn=$dir . self::SITEMAP_PREFIX . $dt . self::EXTENSION_TXT; // sitemap filename in public_html
// if daily sitemap already exits
if(file_exists($fn)){
$arr = preg_split('/\n/', trim(file_get_contents($fn))); // array of links
$i=0; // counter
foreach ($arr as $k=>$lk){
if($arr[$k]==null){unset($arr[$k]);}
if(trim($lk)===trim($sm)){ // link already exist
$i++;
if($i>0){$arr[$k]=null;} // link already exist more than once
}else{
if($k==sizeof($arr)-1){
$k++;
$arr[$k]=$sm;
$arr=implode(self::NEW_LINE, $arr);
$fh=fopen($fn, 'wb');
fwrite($fh, $arr);
fclose($fh);
}
continue;
}
}
}else{
$fh=fopen($fn, 'wb');
fwrite($fh, $sm);
fclose($fh);
}
}
Example of Inputs
a-agilent-technologies-healthcare-nyse-us-39d4
aa-alcoa-basic-materials-nyse-us-159a
aaau-perth-mint-physical-gold-nyse-us-8ed9
aaba-altaba-financial-services-nasdaq-us-26f5
aac-healthcare-nyse-us-e92a
aadr-advisorshares-dorsey-wright-adr-nyse-us-d842
aal-airlines-industrials-nasdaq-us-29eb
aamc-altisource-asset-management-com-financial-services-nyse-us-b46a
aan-aarons-industrials-nyse-us-d00e
aaoi-applied-optoelectronics-technology-nasdaq-us-1dee
aaon-basic-materials-nasdaq-us-238e
aap-advance-auto-parts-wi-consumer-cyclical-nyse-us-1f60
aapl-apple-technology-nasdaq-us-8f4c
aat-assets-real-estate-nyse-us-3598
aau-almaden-minerals-basic-materials-nyse-us-1c57
aaww-atlas-air-worldwide-industrials-nasdaq-us-69f3
aaxj-ishares-msci-all-country-asia-ex-japan-nasdaq-us-c6c4
aaxn-axon-enterprise-industrials-nasdaq-us-0eef
ab-alliancebernstein-units-financial-services-nyse-us-deb1
abac-renmin-tianli-consumer-defensive-nasdaq-us-8701
abb-industrials-nyse-us-a407
abbv-abbvie-healthcare-nyse-us-9aea
abc-amerisourcebergen-healthcare-nyse-us-bd9d
abcb-ameris-bancorp-financial-services-nasdaq-us-df98
abdc-alcentra-capital-financial-services-nasdaq-us-96dd
abeo-abeona-therapeutics-healthcare-nasdaq-us-aa0f
abeow-market-us-d84d
abev-ambev-1-consumer-defensive-nyse-us-a9b4
abg-asbury-automotive-consumer-cyclical-nyse-us-db5f
abil-ability-technology-nasdaq-us-91a6
abio-arca-biopharma-healthcare-nasdaq-us-098e
abm-abm-industries-industrials-nyse-us-bcbc
abmd-abiomed-healthcare-nasdaq-us-2818
abr-arbor-realty-real-estate-nyse-us-68b1
abr-a-arbor-realty-real-estate-nyse-us-8c1d
abr-b-arbor-realty-real-estate-nyse-us-97f2
abr-c-arbor-realty-real-estate-nyse-us-ee81
abt-abbott-laboratories-healthcare-nyse-us-c7fd
abtx-allegiance-bancshares-financial-services-nasdaq-us-6913
abus-arbutus-biopharma-healthcare-nasdaq-us-c23f
ac-associated-capital-financial-services-nyse-us-fca3
aca-arcosa-industrials-nyse-us-b429
Part of sitemap-2019-03-15.txt:
domain.org/equity/equilibrium-estimation/a-agilent-technologies-healthcare-nyse-us-39d4
domain.org/equity/equilibrium-estimation/aa-alcoa-basic-materials-nyse-us-159a
domain.org/equity/equilibrium-estimation/aaau-perth-mint-physical-gold-nyse-us-8ed9
domain.org/equity/equilibrium-estimation/aaba-altaba-financial-services-nasdaq-us-26f5
domain.org/equity/equilibrium-estimation/aac-healthcare-nyse-us-e92a
domain.org/equity/equilibrium-estimation/aadr-advisorshares-dorsey-wright-adr-nyse-us-d842
domain.org/equity/equilibrium-estimation/aal-airlines-industrials-nasdaq-us-29eb
domain.org/equity/equilibrium-estimation/aamc-altisource-asset-management-com-financial-services-nyse-us-b46a
domain.org/equity/equilibrium-estimation/aan-aarons-industrials-nyse-us-d00e
domain.org/equity/equilibrium-estimation/aaoi-applied-optoelectronics-technology-nasdaq-us-1dee
domain.org/equity/equilibrium-estimation/aaon-basic-materials-nasdaq-us-238e
domain.org/equity/equilibrium-estimation/aap-advance-auto-parts-wi-consumer-cyclical-nyse-us-1f60
domain.org/equity/equilibrium-estimation/aapl-apple-technology-nasdaq-us-8f4c
domain.org/equity/equilibrium-estimation/aat-assets-real-estate-nyse-us-3598
domain.org/equity/equilibrium-estimation/aau-almaden-minerals-basic-materials-nyse-us-1c57
domain.org/equity/equilibrium-estimation/aaww-atlas-air-worldwide-industrials-nasdaq-us-69f3
domain.org/equity/equilibrium-estimation/aaxj-ishares-msci-all-country-asia-ex-japan-nasdaq-us-c6c4
domain.org/equity/equilibrium-estimation/aaxn-axon-enterprise-industrials-nasdaq-us-0eef
domain.org/equity/equilibrium-estimation/ab-alliancebernstein-units-financial-services-nyse-us-deb1
domain.org/equity/equilibrium-estimation/abac-renmin-tianli-consumer-defensive-nasdaq-us-8701
domain.org/equity/equilibrium-estimation/abb-industrials-nyse-us-a407
domain.org/equity/equilibrium-estimation/abbv-abbvie-healthcare-nyse-us-9aea
domain.org/equity/equilibrium-estimation/abc-amerisourcebergen-healthcare-nyse-us-bd9d
domain.org/equity/equilibrium-estimation/abcb-ameris-bancorp-financial-services-nasdaq-us-df98
domain.org/equity/equilibrium-estimation/abdc-alcentra-capital-financial-services-nasdaq-us-96dd
domain.org/equity/equilibrium-estimation/abeo-abeona-therapeutics-healthcare-nasdaq-us-aa0f
domain.org/equity/equilibrium-estimation/abeow-market-us-d84d
domain.org/equity/equilibrium-estimation/abev-ambev-1-consumer-defensive-nyse-us-a9b4
domain.org/equity/equilibrium-estimation/abg-asbury-automotive-consumer-cyclical-nyse-us-db5f
domain.org/equity/equilibrium-estimation/abil-ability-technology-nasdaq-us-91a6
domain.org/equity/equilibrium-estimation/abio-arca-biopharma-healthcare-nasdaq-us-098e
domain.org/equity/equilibrium-estimation/abm-abm-industries-industrials-nyse-us-bcbc
domain.org/equity/equilibrium-estimation/abmd-abiomed-healthcare-nasdaq-us-2818
domain.org/equity/equilibrium-estimation/abr-arbor-realty-real-estate-nyse-us-68b1
domain.org/equity/equilibrium-estimation/abr-a-arbor-realty-real-estate-nyse-us-8c1d
domain.org/equity/equilibrium-estimation/abr-b-arbor-realty-real-estate-nyse-us-97f2
domain.org/equity/equilibrium-estimation/abr-c-arbor-realty-real-estate-nyse-us-ee81
domain.org/equity/equilibrium-estimation/abt-abbott-laboratories-healthcare-nyse-us-c7fd
domain.org/equity/equilibrium-estimation/abtx-allegiance-bancshares-financial-services-nasdaq-us-6913
domain.org/equity/equilibrium-estimation/abus-arbutus-biopharma-healthcare-nasdaq-us-c23f
domain.org/equity/equilibrium-estimation/ac-associated-capital-financial-services-nyse-us-fca3
domain.org/equity/equilibrium-estimation/aca-arcosa-industrials-nyse-us-b429
Here is an untested script that embodies how I would run it (unless we are dealing with prohibitively large file sizes).
Collect and prepare all of api strings into a single array.
If the first data of the day, just push the data into a new file.
If the file exists, extract the old data, merge with the new, purge the duplicates, alphabetize, then replace the file contents.
public static function collectAPIData() {
$leading_url = self::PROTOCOL .
self::DOMAIN .
self::SLASH .
self::DIR_URL_KEYWORD_1 .
self::SLASH .
self::DIR_URL_KEYWORD_2 .
self::SLASH;
$fresh_data = [];
// start loop
$fresh_data[] = $leading_url . $your_string_from_the_api;
// end loop
return $fresh_data;
}
public static function storeSitemapData($new_urls) {
if (!$new_urls)) {
return;
}
$fn = __DIR__ .
self::DIR_FRONT_PUBLIC_HTML .
self::SITEMAP_PREFIX .
(new \DateTime('now'))->format('Y-m-d') .
self::EXTENSION_TXT;
if (file_exists($fn)) {
$old_urls = file($fn, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$merged = array_merge($old_urls, $new_urls);
$unique = array_keys(array_flip($merged));
sort($unique);
$new_urls = $unique;
}
file_put_contents($fn, implode(self::NEW_LINE, $new_urls));
}
These static functions could be called something like this:
UpdateStocks::storeSitemapData(UpdateStocks::collectAPIData));
In truth, for higher efficiency I could have differentiated new unique urls, then appended them to the existing file, but I like the idea of keeping the data alphabetized.
$i=0; // counter
foreach ($arr as $k=>$lk){
if($arr[$k]==null)
{unset($arr[$k]);}
if(trim($lk)===trim($sm))
{
if($i>0){$arr[$k]=null;}
$i++;
}
$i++ should come after if statement

PHPWord corrupted file?

My basic PHPWord setup is working.
This is my code:
<?php
require_once 'PhpWord/Autoloader.php';
\PhpOffice\PhpWord\Autoloader::register();
function getEndingNotes($writers)
{
$result = '';
// Do not show execution time for index
if (!IS_INDEX) {
$result .= date('H:i:s') . " Done writing file(s)" . EOL;
$result .= date('H:i:s') . " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB" . EOL;
}
// Return
if (CLI) {
$result .= 'The results are stored in the "results" subdirectory.' . EOL;
} else {
if (!IS_INDEX) {
$types = array_values($writers);
$result .= '<p> </p>';
$result .= '<p>Results: ';
foreach ($types as $type) {
if (!is_null($type)) {
$resultFile = 'results/' . SCRIPT_FILENAME . '.' . $type;
if (file_exists($resultFile)) {
$result .= "<a href='{$resultFile}' class='btn btn-primary'>{$type}</a> ";
}
}
}
$result .= '</p>';
}
}
return $result;
}
// Template processor instance creation
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('template.docx');
// Variables on different parts of document
//$templateProcessor->setValue('vorname', htmlspecialchars('John')); // On section/content
//$templateProcessor->setValue('nachname', htmlspecialchars('Doe')); // On footer
//$templateProcessor->setValue('funktion', htmlspecialchars('Manager'));
// Simple table
$templateProcessor->cloneRow('rowValue', 10);
//clone our things
// Will clone everything between ${tag} and ${/tag}, the number of times. By default, 1.
$templateProcessor->cloneBlock('CLONEME', 5);
//delete things
// Everything between ${tag} and ${/tag}, will be deleted/erased.
$templateProcessor->deleteBlock('DELETEME');
// Saving the document as OOXML file...
$temp_file = tempnam(sys_get_temp_dir(), 'PHPWord');
ob_clean();
$templateProcessor->saveAs($temp_file);
getEndingNotes(array('Word2007' => 'docx'));
header("Content-Disposition: attachment; filename='cv.docx'");
readfile($temp_file); // or echo file_get_contents($temp_file);
unlink($temp_file); // remove temp file
?>
it works well for this Word file.
However when I change something in my word file PHPWord delivers a corupted file. It has something to do with XML Errors. My question is, how can I edit my word file and get a perfectly working file without errors?
Is there a tool to fix XML?
I'm having the same issue and this is the first response through a Google search.
I've discovered that using a "deleteBlock()" function to remove an unneeded section will do something to the template that makes it unable to be opened with MS Word / Google Docs. I'm able to open with Mac Pages just fine, but for some reason the deleteBlock() function is doing something weird with the export.
My edit was instead of using a deleteBlock(), I did:
$templateProcessor->cloneBlock('HOBBYBLOCK', 0);
("Hobbies" was just the name of the section I was avoiding on case by case exports)
Effectively removing the {} block wrappers and
Setting the internal variable / injection point to nothing.
This seemed to resolve my issue. Just a heads up for anyone in the future who finds this and needs help troubleshooting. :^}
I found an answer, while editing the word file word inserts different xml elements between words. I had to edit the file manually in an editor making sure the replace values were not seperated by tags.

Failed to show XML Data with PHP Script

I have about 60000 xml files that i have to insert into a MySQL database. so i thought about making a simple php script that would be executed for once to load data from this xml files and insert it into my db on a localhost.
Before inserting it into my DB i tried to show them on the data on the page but it shows nothing, and its type is NULL.
here is the code :
<?php
$dir = new DirectoryIterator('organismes');
foreach ($dir as $fileinfo) {
if (!$fileinfo -> isDot()) {
$XMLFILE = $fileinfo -> getFilename();
echo $XMLFILE . "<br>\n"; /*the filename shows correctly, so the DirectoryIterator is working*/
$pathtofile = "http://localhost/www/organismes/$XMLFILE"; /*the link to the xml file made with a variable*/
echo $pathtofile . "<br>\n"; /* the link shown is correct */
$xml = simplexml_load_file($pathtofile);
echo gettype($xml) . "<br>\n";
if ($xml == FALSE) {
echo "failed to load xml"; /* this message never shows so the xml file loads correctly */
} else {
$Org = $xml->Organisme->Nom; //this variable $Org gets a NULL Value
echo $Org . "<br>" ;
echo gettype($Org);
}
}
}
?>
when i used a print_r($xml), it shows some data so the file loads correctly.
and here is an example of the xml file that i have :
<Organisme id="adil-01053-01" codeInsee="01053" dateMiseAJour="2013-02-27" pivotLocal="adil">
<Nom>Agence</Nom>
<EditeurSource>A2 A3</EditeurSource>
<Adresse type="géopostale">
<Ligne>34, rue du Général-Delestraint</Ligne>
<CodePostal>01000</CodePostal>
<NomCommune>Bourg-en-Bresse</NomCommune>
<Localisation>
<Latitude>46.196535</Latitude>
<Longitude>5.2191997</Longitude>
<Précision>6</Précision>
</Localisation>
<Accessibilité type="ACC"/></Adresse>
<CoordonnéesNum>
<Téléphone>00000000000</Téléphone>
<Télécopie>00000000000</Télécopie>
<Email>adil.01#wanadoo.fr</Email>
<Url>http://www.adil01.org</Url>
</CoordonnéesNum>
<Ouverture><PlageJ début="vendredi" fin="vendredi"><PlageH début="09:00:00" fin="17:00:00"/></PlageJ><PlageJ début="lundi" fin="jeudi"><PlageH début="09:00:00" fin="18:00:00"/></PlageJ>
</Ouverture>
</Organisme>
so i am trying to figure it out why it doesn't show correctly and why it gets a NULL Value
So brothers if you can help that would be wonderful :)
$pathtofile = "http://www.w3schools.com/xml/note.xml";
$xml = simplexml_load_file($pathtofile);
if ($xml == FALSE) {
echo "failed to load xml";
}
else
{
$A = $xml->to;
echo "$A <br />";
}
Focusing on just that part of the code, it seems to work correctly. Either one of two things are happening. The "$xml->Organisme->Nom;" has a spelling error and/or the xml file being pulled does not include those field names.
For testing do
print_r($xml);
right after
echo "$A <br />";
to get an accurate representation of the xml file being pulled.
Hope this helps.
I am not exactly sure what you want but I assume you want to insert XML data into your database. If that's the case, try this:
function create_xml()
{
$xml = simplexml_load_file("file.xml");
$nodes = new SimpleXMLElement('file.xml', null, true)
or die("cannot create");
$i = 0;
foreach ($nodes->children() as $child)
{
$var= $child->xml_child;
$sql = "INSERT INTO ...)";
mysqli_query($connect, $sql);
$i++;
echo "xml set";
}
}

Simplexml_load_file issue, variable gets NULL Value [duplicate]

I have about 60000 xml files that i have to insert into a MySQL database. so i thought about making a simple php script that would be executed for once to load data from this xml files and insert it into my db on a localhost.
Before inserting it into my DB i tried to show them on the data on the page but it shows nothing, and its type is NULL.
here is the code :
<?php
$dir = new DirectoryIterator('organismes');
foreach ($dir as $fileinfo) {
if (!$fileinfo -> isDot()) {
$XMLFILE = $fileinfo -> getFilename();
echo $XMLFILE . "<br>\n"; /*the filename shows correctly, so the DirectoryIterator is working*/
$pathtofile = "http://localhost/www/organismes/$XMLFILE"; /*the link to the xml file made with a variable*/
echo $pathtofile . "<br>\n"; /* the link shown is correct */
$xml = simplexml_load_file($pathtofile);
echo gettype($xml) . "<br>\n";
if ($xml == FALSE) {
echo "failed to load xml"; /* this message never shows so the xml file loads correctly */
} else {
$Org = $xml->Organisme->Nom; //this variable $Org gets a NULL Value
echo $Org . "<br>" ;
echo gettype($Org);
}
}
}
?>
when i used a print_r($xml), it shows some data so the file loads correctly.
and here is an example of the xml file that i have :
<Organisme id="adil-01053-01" codeInsee="01053" dateMiseAJour="2013-02-27" pivotLocal="adil">
<Nom>Agence</Nom>
<EditeurSource>A2 A3</EditeurSource>
<Adresse type="géopostale">
<Ligne>34, rue du Général-Delestraint</Ligne>
<CodePostal>01000</CodePostal>
<NomCommune>Bourg-en-Bresse</NomCommune>
<Localisation>
<Latitude>46.196535</Latitude>
<Longitude>5.2191997</Longitude>
<Précision>6</Précision>
</Localisation>
<Accessibilité type="ACC"/></Adresse>
<CoordonnéesNum>
<Téléphone>00000000000</Téléphone>
<Télécopie>00000000000</Télécopie>
<Email>adil.01#wanadoo.fr</Email>
<Url>http://www.adil01.org</Url>
</CoordonnéesNum>
<Ouverture><PlageJ début="vendredi" fin="vendredi"><PlageH début="09:00:00" fin="17:00:00"/></PlageJ><PlageJ début="lundi" fin="jeudi"><PlageH début="09:00:00" fin="18:00:00"/></PlageJ>
</Ouverture>
</Organisme>
so i am trying to figure it out why it doesn't show correctly and why it gets a NULL Value
So brothers if you can help that would be wonderful :)
$pathtofile = "http://www.w3schools.com/xml/note.xml";
$xml = simplexml_load_file($pathtofile);
if ($xml == FALSE) {
echo "failed to load xml";
}
else
{
$A = $xml->to;
echo "$A <br />";
}
Focusing on just that part of the code, it seems to work correctly. Either one of two things are happening. The "$xml->Organisme->Nom;" has a spelling error and/or the xml file being pulled does not include those field names.
For testing do
print_r($xml);
right after
echo "$A <br />";
to get an accurate representation of the xml file being pulled.
Hope this helps.
I am not exactly sure what you want but I assume you want to insert XML data into your database. If that's the case, try this:
function create_xml()
{
$xml = simplexml_load_file("file.xml");
$nodes = new SimpleXMLElement('file.xml', null, true)
or die("cannot create");
$i = 0;
foreach ($nodes->children() as $child)
{
$var= $child->xml_child;
$sql = "INSERT INTO ...)";
mysqli_query($connect, $sql);
$i++;
echo "xml set";
}
}

Categories