Simple PHP Function to Display Daily Bing WallPaper


Bing uploads a daily wallpaper, and we can show today’s Bing wallpaper via the following PHP function.

1
2
3
4
5
6
7
<?php
function display_daily_bing_wallpaper() {
    $bing_daily_image_xml = file_get_contents('http://cn.bing.com/HPImageArchive.aspx?idx=0&n=1');
    preg_match("/<urlBase>(.+?)<\/urlBase>/ies", $bing_daily_image_xml, $matches);
    $bing_daily_img_url= 'https://s.cn.bing.com' . $matches[1] . '_1920x1080.jpg';
    echo "<img src='". $bing_daily_img_url. "'>";
}
<?php
function display_daily_bing_wallpaper() {
    $bing_daily_image_xml = file_get_contents('http://cn.bing.com/HPImageArchive.aspx?idx=0&n=1');
    preg_match("/<urlBase>(.+?)<\/urlBase>/ies", $bing_daily_image_xml, $matches);
    $bing_daily_img_url= 'https://s.cn.bing.com' . $matches[1] . '_1920x1080.jpg';
    echo "<img src='". $bing_daily_img_url. "'>";
}

The idea is to invoke the Bing wallpaper API that returns the latest (which is today) wallpaper in XML format. And we are looking for the urlBase values that can be used to retrieve the wallpaper image URL.

This function does not download/store the Bing Picture to your server. It gets the XML and parses the image URL, displays to users, which then downloads the image from your client’s browser.

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
232 words
Last Post: Key Considerations for Developing Online Casino Games
Next Post: How to Download Video via Workflow?

The Permanent URL is: Simple PHP Function to Display Daily Bing WallPaper

Leave a Reply