[php] background image from feed

Status
Niet open voor verdere reacties.

xvilo

Gebruiker
Lid geworden
14 dec 2008
Berichten
492
Hallo,

Ik probeer simple weg een RSS feed om te bouwen tot een mooi html overzichtje... ofzo... hahaha
In iedergeval wil ik dat het plaatje uit de feed word weergegeven als achtergrond plaatje,

ik probeer dat op deze manier:
PHP:
<?php  
        $feed_url = "http://jonginnop.nl/rss/highlights/";
          
        $content = file_get_contents($feed_url);  
        $x = new SimpleXmlElement($content);  
          
        $aantal = 0;
          
        foreach($x->channel->item as $entry) {  
            $title = str_replace('–', '-', $entry->title);  
            $tijd = $entry->pubDate;
            $plaatje = $entry->enclosure[0]->attributes();
            
                      
            echo ' <div class="text" style="background:url('.$plaatje.') no-repeat center center fixed;  -webkit-background-size: cover; -moz-background-size: cover;-o-background-size: cover; background-size: cover;"> ';
            echo'    <h1>'.$title.'</h1>';
            echo'</div>';
            
        }  
?>

Maar nu werkt dus het achtergrond plaatje niet, geen idee waarom eigenlijk! Waarschijnlijk kijk ik er gewoon al wat te lang tegen aan....

//xvilo
 
Heb je een voorbeeld van de waarde van $plaatje?

Gebruik je een debug-tool zoals FireBug of Chrome Developer Tools?
Daar zal ook wel wat informatie in terug te vinden zijn.
 
Heb je een voorbeeld van de waarde van $plaatje?

Gebruik je een debug-tool zoals FireBug of Chrome Developer Tools?
Daar zal ook wel wat informatie in terug te vinden zijn.

Het komt er zo uit te zien:
http://xvilo.com/parse.php

EDIT:
Het gekke is dat als ik dit doe het wel werkt:
PHP:
<?php  
        $feed_url = "http://jonginnop.nl/rss/highlights/";
		  
		$content = file_get_contents($feed_url);  
		$x = new SimpleXmlElement($content);  
		  
		$aantal = 0;
		  
		foreach($x->channel->item as $entry) {  
			$title = str_replace('–', '-', $entry->title);  
			$tijd = $entry->pubDate;
            $plaatje = $entry->enclosure[0]->attributes();
            
                      
            echo ' <div class="text" style="background:url(http://blogimages.bloggen.be/wtc_central/19-9b487bb64d47e7fce068da4c4c159eb7.jpg) no-repeat center center fixed;  -webkit-background-size: cover; -moz-background-size: cover;-o-background-size: cover; background-size: cover;"> ';
            echo'    <h1>'.$title.'</h1>';
            echo'</div>';
            
		}  
?>	
<?php  ?>
<?php echo $nummer . "<br>"; ?>

EDIT 2:
Klein beetje code toegevoegd om de dingen zonder plaatje op te vangen:
PHP:
<?php  
        $feed_url = "http://jonginnop.nl/rss/highlights/";
		  
		$content = file_get_contents($feed_url);  
		$x = new SimpleXmlElement($content);  
		  
		$aantal = 0;
		  
		foreach($x->channel->item as $entry) {  
			$title = str_replace('–', '-', $entry->title);  
			$tijd = $entry->pubDate;
            $plaatje = $entry->enclosure[0]->attributes();
            
            if ($plaatje == "http://jonginnop.nl/upload/"){
                $plaatje = "http://www.online-image-editor.com/styles/2013/images/example_image.png";
            }else{
                //hier komt nog wat extra's
            }
                      
            echo ' <div class="text" style="background:url('.$plaatje.') no-repeat center center fixed;  -webkit-background-size: cover; -moz-background-size: cover;-o-background-size: cover; background-size: cover;"> ';
            echo'    <h1>'.$title.'</h1>';
            echo'</div>';
            
		}  
?>
Het gekke is dus dat de dingen die worden getriggerd door de if statement wel het plaatje laten zien...
 
Laatst bewerkt:
De reden dat ze het niet doen is omdat de afbeeldingen een 404 opleveren:
Code:
Failed to load resource: the server responded with a status of 404 (Not Found) http://jonginnop.nl/upload/blo_imageopendag.jpg
Failed to load resource: the server responded with a status of 404 (Not Found) http://jonginnop.nl/upload/highlightsspuit.jpg
Failed to load resource: the server responded with a status of 404 (Not Found) http://jonginnop.nl/upload/highlightsinstagram.jpg
Failed to load resource: the server responded with a status of 404 (Not Found) http://jonginnop.nl/upload/highlights%C3%83%C5%BEpil.jpg
Failed to load resource: the server responded with a status of 404 (Not Found) http://jonginnop.nl/upload/highlightsgeheim.jpg
Failed to load resource: the server responded with a status of 404 (Not Found) http://jonginnop.nl/upload/highlightsiscrimination-1380779-m.jpg
Failed to load resource: the server responded with a status of 404 (Not Found) http://jonginnop.nl/upload/highlightssterilisation-1385735-m.jpg
Failed to load resource: the server responded with a status of 404 (Not Found) http://jonginnop.nl/upload/blo_image%C3%82%C2%AChtbaan.jpg
Failed to load resource: the server responded with a status of 404 (Not Found) http://jonginnop.nl/upload/albumsnoordoostpolderIMG-20140119-WA0000.jpg
Failed to load resource: the server responded with a status of 404 (Not Found) http://jonginnop.nl/upload/themashighlight.JPG
Failed to load resource: the server responded with a status of 404 (Not Found) http://jonginnop.nl/upload/usg_imageOlivia.jpeg
Failed to load resource: the server responded with a status of 404 (Not Found) http://jonginnop.nl/upload/blo_imagejonginnopcaravan1.jpg
Failed to load resource: the server responded with a status of 404 (Not Found) http://jonginnop.nl/upload/art_imageplaatjedef.jpg
Failed to load resource: the server responded with a status of 404 (Not Found) http://jonginnop.nl/upload/usg_imageProfielfoto_Charlene.jpg
Failed to load resource: the server responded with a status of 404 (Not Found) http://jonginnop.nl/upload/art_imageskeeler.jpg
Failed to load resource: the server responded with a status of 404 (Not Found) http://jonginnop.nl/upload/blo_image%C3%B2%C2%AF%C2%AF%C2%AElding_goodbyebluemonday.PNG
Failed to load resource: the server responded with a status of 404 (Not Found) http://jonginnop.nl/upload/highlights%C3%82%C2%BArbie.jpg
Failed to load resource: the server responded with a status of 404 (Not Found) http://jonginnop.nl/upload/art_image%203_12104124.jpg
Failed to load resource: the server responded with a status of 404 (Not Found) http://jonginnop.nl/upload/art_image%208_94405713.jpg
Failed to load resource: the server responded with a status of 404 (Not Found) http://jonginnop.nl/upload/highlightsregenboogvlag.jpg
Blijkbaar is de URL die in $plaatje komt de staan niet het juiste absolute pad naar de afbeelding.
Kwestie van debuggen welke URL daar uit komt en checken wat er dan mis gaat.
 
tja, helaas heb ik niet die rot website ontworpen hahaha, maar ik heb het wel opgelost! Heb alle spatie's vervangen door %20 en alle "\" vervangen door "/" nu doet ie het wel:
PHP:
<?php  
        $feed_url = "http://jonginnop.nl/rss/highlights/";
		  
		$content = file_get_contents($feed_url);  
		$x = new SimpleXmlElement($content);  
		  
		$aantal = 0;
		  
		foreach($x->channel->item as $entry) {  
			$title = str_replace('–', '-', $entry->title);  
			$tijd = $entry->pubDate;
            $plaatje = $entry->enclosure[0]->attributes();
            
            if ($plaatje == "http://jonginnop.nl/upload/"){
                $plaatje = "http://www.online-image-editor.com/styles/2013/images/example_image.png";
            }else{
                $plaatje = str_replace("\\", "/", $plaatje);
                $plaatje = str_replace(" ", "%20", $plaatje);
            }
                      
            echo ' <div class="text" style="background:url('.$plaatje.') no-repeat center center fixed;  -webkit-background-size: cover; -moz-background-size: cover;-o-background-size: cover; background-size: cover;"> ';
            echo'    <h1>'.$title.'</h1>';
            echo'</div>';
            
		}  
?>
 
Laatst bewerkt door een moderator:
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan