i have done a curl request and got what i needed in $resp.
this is my code:
$dom = new DOMDocument();
#$dom->loadHTML($resp);
foreach($dom->getElementsByTagName('img') as $image) {
$image->getAttribute('src');
if strcmp( $image, "images/Balls/"){
echo substr($image, -6,-7);
}
echo "<br />";}
this does not work because $image is not a string... how can i make this code work? All i need to do is to convert $image to string.
Thanks in advance
You're not doing anything with $image->getAttribute() except just calling it. You need to assign the result of $image->getAttribute() to a variable, and then pass that variable to strcmp().
Related
Below is my json respone:
{"Status":"OK","Result":"{\"Cookie\":MyCookie",\"Data\":{\"ItemPhotos\":[{
\"ITEMID\":\"MyItemsID",
\"ITEMIMAGE\":\"/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAC0AUADASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEh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xK5XgIWG38sc1b8PaXbWWg2kcClFKbyBgcnrRRSglyoVVtyZzvjXw5p8VgdRijaOcvhghAVvcjHX6V5nMgBPJ4ooqJfEdVB3hqRxsyNwxq2kj7fvUUVnI6okF3fTwRlkfmut8M6LbXNvFeTvLLMwzliCB9BjiiisqmkTeO531haRoi4LfnWkbZNvVulFFYR2Oee41LdORlqelsnmry3UUUV6FL4EeVX/AIjP/9k=\",
\"IMAGEID\":\"ImageID",
\"IMAGEDESCR\":\"xxx.jpg\",
\"IMAGETYPE\":\"TheImageType\",
\"IMAGESIZE\":\"320 x 240\"},]},
\"Messages\":[]}","Error":null,"ErrorCode":null,"Benchmark":0}
I want to diplay the image of json response and i use the code below unsuccessfully
$image=json_decode($decoded['Result']);
$path=$image->Data->ItemPhotos[0]->{'ITEMIMAGE'};
$icon=glob($path."*.jpeg");
foreach($icon as $img) {
echo '<img src="'.$img.'" /><br />';
}
You have two quick solutions for this. One is to persist the encoded image and append the path to the image src. Another solution is to process the json and use the base 64 processor in correct format eg:- 'data:image/png;base64,' + <base 64 encoded image>
or,
'data:image/jpg;base64,' + <base 64 encoded image>
I created a snippet that works with your use case. You have to refactor it a bit to accommodate your changes.
<?php
// Lets assugme you receive this json response
$json = '{
"ITEMIMAGE": "/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAC0AUADASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0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q1FFMESi2THVvzp4tU9W/OiimUP+yp6t+dO+yp6t+dFFADhap6t+dZPiKMw6cvlyOu99rYPUY6UUUPYZiWOnxuAfNmH0bFXljZJCizyYBx2/woooewdTThg+XmVz9cf4U82cEhxJGkn+8in+lFFWiHuMl0jTyhzZwf8Aftf8Kpf2DpczYazQf7pIoooFdjx4T0gjP2c/99mkbw3pcIylv+ZoooC7KRtYoGIjXaKvWyZA+ZqKKYGnBCCBy1XUt1/vN+dFFIaHiIKeGb8ak8pCORRRTRSIjCIpV2M2HOCvasjVtFswvmqrKSegPFFFY1kuQ1ot8xzd/wCF9OudLnuJxK5XgIWG38sc1b8PaXbWWg2kcClFKbyBgcnrRRSglyoVVtyZzvjXw5p8VgdRijaOcvhghAVvcjHX6V5nMgBPJ4ooqJfEdVB3hqRxsyNwxq2kj7fvUUVnI6okF3fTwRlkfmut8M6LbXNvFeTvLLMwzliCB9BjiiisqmkTeO531haRoi4LfnWkbZNvVulFFYR2Oee41LdORlqelsnmry3UUUV6FL4EeVX/AIjP/9k=",
"IMAGEID": "ImageID",
"IMAGEDESCR": "xxx.jpg",
"IMAGETYPE": "TheImageType",
"IMAGESIZE": "320 x 240"
}';
$decode = json_decode($json);
// you need base 64 processor
$processor = "";
if($decode->IMAGEDESCR == "xxx.jpg") {
$processor = "data:image/jpg;base64,";
} elseif ($decode->IMAGEDESCR == "xxx.png") {
$processor = "data:image/png;base64,";
}
$img_src = $processor . $decode->ITEMIMAGE;
echo '<img src='.$img_src.'/>';
?>
Your src attribute for the img tag will be something like this
'data:image/png;base64,' + $path;
you must inform that the image is encoded base64 (I suppose it is) and also specify the kind of data (image/png) in my example
I have a page test.php in which I have a list of names:
name1: 992345
name2: 332345
name3: 558645
name4: 434544
In another page test1.php?id=name2 and the result should be:
332345
I've tried this PHP code:
<?php
libxml_use_internal_errors(true);
$doc = new DOMDocument();
$doc->loadHTMLFile("/test.php");
$xpath = new DOMXpath($doc);
$elements = $xpath->query("//*#".$_GET["id"]."");
if (!is_null($elements)) {
foreach ($elements as $element) {
$nodes = $element->childNodes;
foreach ($nodes as $node) {
echo $node->nodeValue. "\n";
}
}
}
?>
I need to be able to change the name with GET PHP method in test1.pdp?id=name4
The result should be different now.
434544
is there another way, becose mine won't work?
Here is another way to do it.
<?php
libxml_use_internal_errors(true);
/* file function reads your text file into an array. */
$doc = file("test.php");
$id = $_GET["id"];
/* Show your array. You can remove this part after you
* are sure your text file is read correct.*/
echo "Seeking id: $id<br>";
echo "Elements:<pre>";
print_r($doc);
echo "</pre>";
/* this part is searching for the get variable. */
if (!is_null($doc)) {
foreach ($doc as $line) {
if(strpos($line,$id) !== false){
$search = $id.": ";
$replace = '';
echo str_replace($search, $replace, $line);
}
}
} else {
echo "No elements.";
}
?>
There is a completely different way to do this, using PHP combined with JavaScript (not sure if that's what you're after and if it can work with your app, but I'm going to write it). You can change your test.php to read the GET parameter (it can be POST as well, you'll see), and according to that, output only the desired value, probably from the associative array you have hard-coded in there. The JavaScript approach will be different and it would involve making a single AJAX call instead of DOM traversing using PHP.
So, in short: AJAX call to test.php, which then output the desired value based on the GET or POST parameter.
jQuery AJAX here; native JS tutorial here.
Just let me know if this won't work for your app, and I'll delete my answer.
I am querying image using getElementsByTagName("img") and printing it using image->src , it does not work. I also tried to use image->nodeValue this to does not work.
require('simple_html_dom.php');
$dom=new DOMDocument();
$dom->loadHTML( $str); /*$str contains html output */
$xpath=new DOMXPath($dom);
$imgfind=$dom->getElementsByTagName('img'); /*finding elements by tag name img*/
foreach($imgfind as $im)
{
echo $im->src; /*this doesnt work */
/*echo $im->nodeValue; and also this doesnt work (i tried both of them separately ,Neither of them worked)*/
// echo "<img src=".$im->nodeValue."</img><br>"; //This also did not work
}
/*the image is encolsed within div tags.so i tried to query value of div and print but still image was not printed*/
$printimage=$xpath->query('//div[#class="abc"]');
foreach($printimage as $image)
{
echo $image->src; //still i could not accomplish my task
}
Okay, use this to display your image:
foreach($imgfind as $im)
{
echo "<img src=".$im->getAttribute('src')."/>"; //use this instead of echo $im->src;
}
and it will surely display your image. Make sure path to the image is correct.
Espero te sirva
$dom = new DOMDocument();
$filename = "https://www.amazon.com/dp/B0896WB9XD/";
$html = file_get_contents($filename);
#$dom->loadHTML($html);
$imgfind=$dom->getElementsByTagName('img');
foreach($imgfind as $im)
{
$ids= $im->getAttribute('id');
if ($ids == 'landingImage') {
$im2 = $im->getAttribute('src');
echo '<img src="'.$im2.'">';
}
else{
}
}
para amazon.
I have the following code that replaces all tags on a page and adds the nCode image resizer to it. The code is as follows:
function ncode_the_content($content) {
return preg_replace("/<img([^`|>]*)>/im", "<img onload=\"NcodeImageResizer.createOn(this);\"$1>", $content); }
}
What I need to do is make it so that if an image has the class of "noresize" it doesn't do the preg_match.
I have only managed to get it so that if there is the "noresize" class anywhere on the page it stops resizing all images instead of just the one with the correct class.
Any suggestions?
UPDATE:
Am I even remotely in the right ballpark with this?
function ncode_the_content($content) {
//Load the HTML page
$html = file_get_contents($content);
//Parse it. Here we use loadHTML as a static method
//to parse the HTML and create the DOM object in one go.
#$dom = DOMDocument::loadHTML($html);
//Init the XPath object
$xpath = new DOMXpath($dom);
//Query the DOM
$linksnoresize = $xpath->query( 'img[#class = "noresize"]' );
$links = $xpath->query( 'img[]' );
//Display the results as in the previous example
foreach($links as $link){
echo $link->getAttribute('onload'), 'NcodeImageResizer.createOn(this);';
}
foreach($linksnoresize as $link){
echo $link->getAttribute('onload'), '';
}
}
Here's some untested code:
$dom = DOMDocument::loadHTML($content);
$images = $dom->getElementsByTagName("img");
foreach ($images as $image) {
if (!strstr($image->getAttribute("class"), "noresize")) {
$image->setAttribute("onload", "NcodeImageResizer.createOn(this);");
}
}
But, if it were me, I would eschew any such inline event handler and instead just find the appropriate elements with Javascript.
I ended up just using pure CSS and adding a around the images I didn't want to be resized. Forced the width and height of that div back to auto and then removed the warning message that was displayed above them. Seems to work fine. Thanks for your help :)
I just can't seem to be able to solve this. I want to get the media:thumbnail from an RSS file (http://feeds.bbci.co.uk/news/rss.xml).
I did some research and tried to incorporate insights from
https://stackoverflow.com/questions/6707315/getting-xml-attribute-from-mediathumbnail-in-bbc-rss-feed
and from other sources.
This is what I got:
$source_link = "http://feeds.bbci.co.uk/news/rss.xml";
$source_xml = simplexml_load_file($source_link);
$namespace = "http://search.yahoo.com/mrss/";
foreach ($source_xml->channel->item as $rss) {
$title = $rss->title;
$description = $rss->description;
$link = $rss->link;
$date_raw = $rss->pubDate;
$date = date("Y-m-j G:i:s", strtotime($date_raw));
$image = $rss->attributes($namespace);
print_r($image);
}
When I run the script, all I see is a white page. If I echo or print_r any of the other variables, then it works like a charm. It's just the $image one which poses problems. Why isn't this working? Thx for any help!
OK, it works now. I replaced
$image = $rss->attributes($namespace);
with
$image = $rss->children($namespace)->thumbnail[1]->attributes();
$image_link = $image['url'];
and it works like a charm now.
Base from this blog, with post title Processing media:thumbnail in RSS feeds with php.
The solution that I found works best simply loads the xml file as a string, then find and replace 'media:thumbnail' with a correctly formatted 'thumbnail' and lastly convert it back to xml with simplexml_load_string:
$xSource = 'http://feeds.bbci.co.uk/news/rss.xml';
$xsourcefile = file_get_contents( $xSource );
$xsourcefile = str_replace("media:thumbnail","thumbnail",$xsourcefile);
$xml = simplexml_load_string( $xsourcefile );
echo $row['xtitle'] . '<BR>';
foreach ($xml->channel->item as $item) {
echo ':' . $item->title . '<BR>';
echo ':' . $item->thumbnail['url'] . '<BR>';
}
$image = $rss->attributes($namespace);
This says "Give me all attributes of this <item> element which are in the media namespace". There are no attributes on the item element (much less any in the media namespace), so this returns nothing.
You want this:
$firstimage = $rss->children($namespace)->thumbnail[0];
BTW, when you use SimpleXML you need to be careful to cast your SimpleXMLElements to string when you need the text value of the element. Something like $rss->title is a SimpleXMLElement, not a string.