I use this code for get all images from my account picasa but without result :
$content = file_get_contents("https://picasaweb.google.com/data/feed/base/user/107745136468823194427?alt=rss&kind=photo&hl=fr&imgmax=1600");
$x = new SimpleXmlElement($content);
foreach($x->channel->item as $entry => $value){
$title = $value->title;
$image = $value->enclosure->attributes()->url;
$urlimg = $image[0];
echo '<img src="'.$urlimg.'>"';
}
What the problem ? Thanks
Can you try with this code please?
<?php
$content = file_get_contents("https://picasaweb.google.com/data/feed/base/user/107745136468823194427?alt=rss&kind=photo&hl=fr&imgmax=1600");
$x = simplexml_load_string($content);
foreach($x->channel->item as $entry => $value){
$title = $value->title;
$image = $value->enclosure->attributes()->url;
$urlimg = $image[0];
echo '<img src="'.$urlimg.'>"';
}
Related
I can not get the tumbnail images using the following code. What i need to do to get a tumbnail images from google rss feed. Anyone can help me please ?
$news = simplexml_load_file('https://news.google.com/news?pz=1&cf=all&ned=en&hl=en&topic=n&output=rss');
$feeds = array();
$i = 0;
foreach ($news->channel->item as $item)
{
preg_match('~<img[^>]*src\s?=\s?[\'"]([^\'"]*)~i',$item->description, $imageurl);
//preg_match('#src="([^"]+)"#', $item->description, $imageurl);
$parts = explode('<font size="-1">', $item->description);
$feeds[$i]['title'] = (string) $item->title;
$feeds[$i]['link'] = (string) $item->link;
$feeds[$i]['image'] = $imageurl[1];
$feeds[$i]['site_title'] = strip_tags($parts[1]);
$feeds[$i]['story'] = strip_tags($parts[2]);
$i++;
}
echo '<pre>';
print_r($feeds);
echo '</pre>';
I installed a php reader for Google News on my website to read the first five articles but (1) the images don't display, and (2) I would like only the first source article of the master title.
$news = simplexml_load_file('https://news.google.com/news?q=guadeloupe&output=rss&hl=fr&ned=fr&num=5');
$feeds = array();
$i = 0;
foreach ($news->channel->item as $item)
{
$parts = explode('<td', $item->description);
$titre = explode('<div class="lh">', $item->description);
$feeds[$i]['description'] = (string) $item->description;
$feeds[$i]['title'] = (string) $item->title;
$feeds[$i]['link'] = (string) $item->link;
if (isset($parts[1])) {
$feeds[$i]['site_title'] = strip_tags($parts[1]);
}
$RSS_title = (string) $item->title;
$RSS_link = (string) $item->link;
if (isset($parts[2])) {
$RSS_part2 = $parts[2];
$RSS_part2 = str_replace('valign="top" class="j">','',$RSS_part2);
$RSS_part2 = str_replace('<a href=','<a class="lienviolet15B" style="font-size:14px;" target="_blank" href=',$RSS_part2);
echo "$RSS_part2";
}
$i++;
}
RiggsFolly, num=1 list only one news and i want 5 news ;)
i found the solution and give my code for a php google news reader on specific query :
<?php
// clean cut function
function cleanCut($string,$length,$cutString = '...'){
if(strlen($string) <= $length) {
return $string; }
$str = substr($string,0,$length-strlen($cutString)+1);
return substr($str,0,strrpos($str,' ')).$cutString;
}
//// google news => list 5 news on special query, here "formule 1"
//// if query have space or special chars use urlencode($myquery)
//// replace language value in rss url (here "fr" for french)
$myquery = "formule 1";
$myquery = urlencode($myquery);
$news = simplexml_load_file('https://news.google.com/news?q='.$myquery.'&output=rss&hl=fr&ned=fr&num=5');
$feeds = array();
$i = 0;
foreach ($news->channel->item as $item) {
preg_match('#src="([^"]+)"#', $item->description, $match);
$parts = explode('<font size="-1">', $item->description);
$feeds[$i]['title'] = (string) $item->title;
$feeds[$i]['link'] = (string) $item->link;
$feeds[$i]['image'] = $match[1];
$feeds[$i]['site_title'] = strip_tags($parts[1]);
$feeds[$i]['story'] = strip_tags($parts[2]);
$i++;
$RSS_title = (string) $item->title;
$RSS_title = substr($RSS_title, 0, strpos($RSS_title, "-")); // delete source site in title
$RSS_title = cleanCut($RSS_title, 60); // (option) clean cut title after 60 char
$RSS_link = (string) $item->link; // extract link
$RSS_story = strip_tags($parts[2]); // extract begin article
$RSS_story = cleanCut($RSS_story, 260); // (option) clean cut article after 260 char
$RSS_image = $match[1]; // extract image
$RSS_source = strip_tags($parts[1]); // extract source site
if ($RSS_image!="") { // only article with image
echo "<div class=\"row\" style=\"margin-bottom:20px;\">";
echo "<div class=\"col-xs-12\">";
echo "<img src=\"".$RSS_image."\" style=\"width:80px;float:left;margin:0px 10px\">";
echo "<a class=\"lienviolet15B\" style=\"font-size:14px;\" target=\"_blank\" href=\"".$RSS_link."\">";
echo "".$RSS_title."";
echo "</a><br>";
echo "".$RSS_story."<br>";
echo "<div class=\"pull-right\"><i>".$RSS_source."</i></div>";
echo "</div></div>";
}
}
//echo '<pre>'; print_r($feeds); echo '</pre>'; // rss brut
?>
I'm using a php to code to fetch images and data from the other urls
but need to convert images to base64 string..!!
the code is
<?php
function getMetaTitle($content){
$pattern = "|<[\s]*title[\s]*>([^<]+)<[\s]*/[\s]*title[\s]*>|Ui";
if(preg_match($pattern, $content, $match))
return $match[1];
else
return false;
}
function fetch_record($path)
{
$file = fopen($path, "r");
if (!$file)
{
exit("Problem occured");
}
$data = '';
while (!feof($file))
{
$data .= fgets($file, 1024);
}
return $data;
}
$url = $_POST['url'];
$data = array();
// get url title
$content = #file_get_contents($url);
$data['title'] = getMetaTitle($content);
// get url description from meta tag
$tags = #get_meta_tags($url);
$data['description'] = $tags['description'];
$string = fetch_record($url);
// fetch images
$image_regex = '/<img[^>]*'.'src=[\"|\'](.*)[\"|\']/Ui';
preg_match_all($image_regex, $content, $img, PREG_PATTERN_ORDER);
$images_array = $img[1];
$k=1;
for ($i=0;$i<=sizeof($images_array);$i++)
{
if(#$images_array[$i])
{
if(#getimagesize(#$images_array[$i]))
{
list($width, $height, $type, $attr) = getimagesize(#$images_array[$i]);
if($width > 50 && $height > 50 ){
$data['images'] = "<img src='".#$images_array[$i]."' id='".$k."' width='100%'>";
$k++;
}
}
}
}
$data['form'] = '<input type="hidden" name="images" value="'.$data['images'].'"/>
<input type="hidden" name="title" value="'.$data['title'].'"/>
<input type="hidden" name="description" value="'.$data['description'].'"/>';
$dom = new domDocument;
#$dom->loadHTML($content);
$dom->preserveWhiteSpace = false;
$images = $dom->getElementsByTagName('img');
foreach($images as $img)
{
$url = $img->getAttribute('src');
$alt = $img->getAttribute('alt');
$pos = strpos($url, 'http://');
if ($pos === false) {
// $data['images'] = '<img src="'.$_POST['url'].''.$url.'" title="'.$alt.'"/>';
} else {
// $data['images'] = '<img src="'.$url.'" title="'.$alt.'"/>';
}
}
echo json_encode($data);
?>
This code use images in there Standard extension on this line
$data['images'] = "<img src='".#$images_array[$i]."' id='".$k."' width='100%'>";
I want to convert them to base64 and them use
Once you have the url for the image you just need to grab it with curl and call base64_encode.
chunk_split just makes it perdy.
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true );
$ret_val = curl_exec($curl);
// TODO: error checking!!!
$b64_image_data = chunk_split(base64_encode($ret_val));
curl_close($curl);
Another option is to get PHP to filter the image's binary data into a Base64 encoded value with a stream conversion filter (docs).
$img_url = 'http://www.php.net/images/php.gif';
$b64_url = 'php://filter/read=convert.base64-encode/resource='.$img_url;
$b64_img = file_get_contents($b64_url);
echo $b64_img;
i have a small problem in figuring out a path to a image var.
here is what happens. this is the image tag:
<img src="http://www.xxx.info/wp-content/uploads/http://ecx.images-amazon.com/images/I/51AV8B7CT2L._SL160_.jpg" class="attachment-135x135 wp-post-image" alt="Clean & Sober" title="Clean & Sober">
and this is how i would like it to be, without the http://www.xxx.info/wp-content/uploads/:
<img src="http://ecx.images-amazon.com/images/I/51AV8B7CT2L._SL160_.jpg" class="attachment-135x135 wp-post-image" alt="Clean & Sober" title="Clean & Sober">
here is the wordpress code:
<?php $thumb = '';
$width = 135;
$height = 135;
$classtext = '';
$titletext = get_the_title();
$thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext,false,'Entry');
$thumb = $thumbnail["thumb"]; ?>
<?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext); ?>
more related functions:
/* this function prints thumbnail from Post Thumbnail or Custom field or First post image */
function print_thumbnail($thumbnail = '', $use_timthumb = true, $alttext = '', $width = 100, $height = 100, $class = '', $echoout = true, $forstyle = false, $resize = true, $post='') {
if ( $post == '' ) global $post;
$output = '';
$thumbnail_orig = $thumbnail;
$thumbnail = et_multisite_thumbnail($thumbnail);
$cropPosition = get_post_meta($post->ID, 'etcrop', true) ? get_post_meta($post->ID, 'etcrop', true) : '';
if ($cropPosition <> '') $cropPosition = '&a=' . $cropPosition;
if ($forstyle === false) {
if ($use_timthumb === false) {
$output = $thumbnail_orig;
} else {
$output = '<img src="'.get_bloginfo('template_directory').'/timthumb.php?src='.$thumbnail.'&h='. $height .'&w='. $width .'&zc=1&q=90'.$cropPosition.'"';
if ($class <> '') $output .= " class='$class' ";
$output .= " alt='$alttext' width='$width' height='$height' />";
if (!$resize) $output = $thumbnail;
}
} else {
$output = $thumbnail;
if ($use_timthumb === false) {
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $output, $matches);
$output = $matches[1][0];
} else {
$output = get_bloginfo('template_directory').'/timthumb.php?src='.$output.'&h='.$height.'&w='.$width.'&q=90&zc=1'.$cropPosition;
}
}
if ($echoout) echo $output;
else return $output;
}
this is what i get returned $output = $thumbnail_orig; in the image tag.
i know that there should be a var for http://www.xxx.info/wp-content/uploads/
and another one for http://ecx.images-amazon.com/images/I/51AV8B7CT2L._SL160_.jpg
i want to remove the the website path to uploads.
i cant seem to figure it out,
All help appreciated,
Thanks
I might be wrong or misunderstanding the question, but I thought setting the path in WP is as simple as editing it in the admin panel, under settings, no?
DC
Here is the PHP im using to read XML:
$url = "images.xml";
$xmlstr = file_get_contents($url);
$xml = new SimpleXMLElement($xmlstr);
foreach ($xml->image as $image) {
$id = $image->id;
$link = $image->href;
$src = $image->source;
$title = $image->title;
$alt = $image->alt;
echo "<a href='$link'><img src='$src' alt='$alt' title='$title' /></a>";
}
The XML contains an ID: $id = $image->id;
I need to sort the output by that ID. How can I do this within the foreach?
if id is unique i will do something like
<?php
$url = "images.xml";
$xmlstr = file_get_contents($url);
$xml = new SimpleXMLElement($xmlstr);
$images = array();
foreach ($xml->image as $image) {
$id = $image->id;
$images[$id]['id'] = $id;
$images[$id]['link'] = $image->href;
$images[$id]['src'] = $image->source;
$images[$id]['title'] = $image->title;
$images[$id]['alt'] = $image->alt;
}
ksort ($images);
foreach ($images as $image){
echo "<a href='".$image['link']."'><img src='".$image['src']."' alt='".$image['alt']."' title='".$image['title']."' /></a>";
}
?>
And if id is not unique then try this
<?php
$url = "images.xml";
$xmlstr = file_get_contents($url);
$xml = new SimpleXMLElement($xmlstr);
$images = array();
$ids = array();
foreach ($xml->image as $image) {
$images[]['id'] = $image -> id;
$images[]['link'] = $image->href;
$images[]['src'] = $image->source;
$images[]['title'] = $image->title;
$images[]['alt'] = $image->alt;
$ids[] = $image -> id;
}
array_multisort($ids, SORT_ASC, $images);
foreach ($images as $image){
echo "<a href='".$image['link']."'><img src='".$image['src']."' alt='".$image['alt']."' title='".$image['title']."' /></a>";
}
?>
These are some quick ones. But these will do the job.