Ja, die kan je converteren naar eigen formaat.
Link gekopieerd
Super bedankt allemaal,
kom steeds wat verder...
hij zet ze nu netjes in de database, controleert of hij al bestaat enz...
alleen.....
<?php
if( preg_match('/^(.*) Set USB ID: (.*) Time: (.*) Engine Hours: (.*)$/', $item->description, $match ) )
{
echo '<pre>' . print_r( $match, TRUE ) . '</pre>';
}
foreach ( $match as $key => $value )
{
echo $key . ' = ' . $value . '<br />';
}
$test = preg_match('/^(.*) Set USB (.*) Time: (.*) Engine (.*)$/', $item->description, $match ) ;
// alleen om te testen
echo '<pre>' . print_r( $test, TRUE ) . '</pre>';
echo '<pre>' . print_r( $match, TRUE ) . '</pre>';
$test1 = $match[1];
$test2 = $match[2];
$test3 = $match[3];
$test4 = $match[4];
echo '<p>' .
$test1 . '<br >' .
$test2 . '<br />' .
$test3 . '<br />' .
$test4 .
'</p>';
?>
dat stukje code lijkt hij niet uit te voeren..
hij staat wel in het stukje waar code wordt uitgevoerd dus dat is het probleem niet..
[size=xsmall]
Toevoeging op 02/11/2020 12:39:55: [/size]
output echo $item->description;
Engine Stopped
Set USB ID: 6B230001F9
Time: 02-11-2020 12:21:11 CET
Engine Hours: 11162:11:34
Link gekopieerd
Doe eerst dit ;
<?php
$description = str_replace(array("\n", "\r"), ' ', $item->description);
?>
Dan dit ;
<?php
preg_match('/^(.*) Set USB ID: (.*) Time: (.*) Engine Hours: (.*)$/', $description, $match )
?>
Link gekopieerd
Adoptive Solution op 02/11/2020 13:27:14
Doe eerst dit ;
<?php
$description = str_replace(array("\n", "\r"), ' ', $item->description);
?>
Dan dit ;
<?php
preg_match('/^(.*) Set USB ID: (.*) Time: (.*) Engine Hours: (.*)$/', $description, $match )
?>
dan krijg ik dit als output :
Fuel Remaining 49% Set USB ID: 6F22683C19 Time: 03-11-2020 02:19:40 CET Engine Hours: 3152:15:00
maarblijven de variabelen alsnog leeg. $match en $test doen niks
Link gekopieerd
Wat ik ook die, het wil maar niet fout gaan.
<?php
// eerdere info
$xml = '<?xml version="1.0" encoding="utf-8"?>
<product>
<description>
Engine Stopped
Set USB ID: 6B230001F9
Time: 02-11-2020 12:21:11 CET
Engine Hours: 11162:11:34</description>
</product>';
// nieuwe info
$xml = '<?xml version="1.0" encoding="utf-8"?>
<product>
<description>Fuel Remaining 49%
Set USB ID: 6F22683C19
Time: 03-11-2020 02:19:40 CET
Engine Hours: 3152:15:00
</description>
</product>';
$item = simplexml_load_string( $xml );
echo '<pre>' . print_r( $item, TRUE ) . '</pre>';
$description = str_replace(array("\n", "\r"), ' ', $item->description);
echo $description . '<br /><br />';
if( preg_match('/^(.*) Set USB ID: (.*) Time: (.*) Engine Hours: (.*)$/', $description, $match ) )
{
echo '<pre>' . print_r( $match, TRUE ) . '</pre>';
}
foreach ( $match as $key => $value )
{
echo $key . ' = ' . $value . '<br />';
}
?>
<hr />
<?php
$test = preg_match('/^(.*) Set USB (.*) Time: (.*) Engine (.*)$/', $description, $match ) ;
// alleen om te testen
echo '<pre>' . print_r( $match, TRUE ) . '</pre>';
$test1 = $match[1];
$test2 = $match[2];
$test3 = $match[3];
$test4 = $match[4];
echo '<p>' .
$test1 . '<br >' .
$test2 . '<br />' .
$test3 . '<br />' .
$test4 .
'</p>';
?>
[size=xsmall]
Toevoeging op 03/11/2020 09:20:21: [/size]
En doe dit eens im de werkelijk inhoud van de opgehaalde data te tonen.
$url = 'https://www.site.com/user_rss_feed.php';
$content = file_get_contents( $url );
echo '<pre>' . print_r( htmlentities( $content ), TRUE ) . '</pre>';
En dump hier dan de description.
Want nu blijft het gissen.
Link gekopieerd
zelfs als ik dit in de w3schools online try it doe werkt hij niet
<?php
$description = "Fuel Remaining 49% Set USB ID: 6F22683C19 Time: 03-11-2020 02:19:40 CET Engine Hours: 3152:15:00 ";
$description = str_replace(array("\n", "\r"), ' ', $description);
$description = html_entity_decode($description);
$description = preg_replace('/(( )+|(\\n)+)/', '$2$3',$description);
//echo $description;
// preg_match('/^(.*) Set USB ID: (.*) Time: (.*) Engine Hours: (.*)$/', $item->description, $match );
if( preg_match('/^(.*) Set USB ID: (.*) Time: (.*) Engine Hours: (.*)$/', $description, $match ) )
{
echo '<pre>' . print_r( $match, TRUE ) . '</pre>';
}
foreach ( $match as $key => $value )
{
echo $key . ' = ' . $value . '<br />';
}
?>
[size=xsmall]
Toevoeging op 03/11/2020 09:36:39: [/size]
echo '<pre>' . print_r( htmlentities( $data ), TRUE ) . '</pre>';
output
Battery Voltage Set USB ID: 6B230001F9 Time: 03-11-2020 06:34:38 CET Engine Hours: 11168:38:54
Link gekopieerd
De sandbox van
https://3v4l.org/ vind ik lekkerder werken. Die kent ook een hele berg aan PHP-versies, en geeft ook de verschillen in de output aan.
Link gekopieerd
Link gekopieerd
- Ariën - op 03/11/2020 09:38:11
De sandbox van https://3v4l.org/ vind ik lekkerder werken. Die kent ook een hele berg aan PHP-versies.
ook daar krijg ik geen goed resultaat
[size=xsmall]
Toevoeging op 03/11/2020 09:48:24: [/size]
Nu snap ik er helemaal niks meer van ;-)
code werkt inderdaad nu op w3schools maar als ik dit doe
krijg ik weer lege array's
<?php
$description = str_replace(array("\n", "\r"), ' ', $item->description);
$description = html_entity_decode($description);
$description = preg_replace('/(( )+|(\\n)+)/', '$2$3',$description);
//echo $description;
if( preg_match('/^(.*) Set USB ID: (.*) Time: (.*) Engine Hours: (.*)$/', $description, $match ) )
{
echo '<pre>' . print_r( $match, TRUE ) . '</pre>';
}
foreach ( $match as $key => $value )
{
echo $key . ' = ' . $value . '<br />';
}
preg_match('/^(.*) : (.*) - (.*) $/', $item->title, $match2 );
echo '<pre>2e match' . print_r( $match2, TRUE ) . '</pre>';
foreach ( $match2 as $key => $value )
{
echo $key . ' = ' . $value . '<br />';
}
Link gekopieerd
Dat komt omdat $item->description niet bestaat.
Link gekopieerd