Get Exif_IFD_Pointer => 2110 [Comments] from image.jpg (PHP) - php

I'm trying to get the comment information from a JPG. My example below returns ?
Because it's grabbing the wrong comment.
[WINXP] => Array ( [Comments] => ????????????????????????????????? )
 
While I need it to grab specifically,
[IFD0] => Array ( [Exif_IFD_Pointer] => 2110 [Comments]
 
 
Code:
<?php
$exif_data = exif_read_data('28058990_1835355009821464_5937004451156759325_n.jpg', 0, true);
echo $exif_data===false ? "No header data found.<br />\n" : "Image contains headers<br />\n";
echo $exif_data['Comments'];
print_r($exif_data);
?>

I ended up doing it this way..
<?php
$exif_data=exif_read_data('28058990_1835355009821464_5937004451156759325_n.jpg', 0, true);
$values=array();
foreach($exif_data as $exif => $key)
{
foreach($key as $value)
{
$items[] = $value;
}
}
echo '<img src='.$items[0].' width="256px"><br />'.$items[12];
?>

Related

How can I separate the output of the web service?

I get this result from web service in php code:
> stdClass Object (
> [Post_Added_Record_ByMenuIDResult] => stdClass Object
> (
> [HTMLStructure] => ثبت انجام شد
> [IsAuthenticated] => 1
> [MenuID] => 1191
> [Password] =>
> [PersonID] => 27598
> [PersonalityID] => 31413
> [RecordValues] =>
> [RoleID] => 5
> [Sexuality_Title] => m
> [UserName] => mr.piri
> ) )
I want to get the opposite phrase in [HTMLStructure]. in this example : ثبت انجام شد
if (strstr( $result, 'HTMLStructure' ) ) {
$HTMLStructurePos=strpos( $result, '[HTMLStructure] =>' );
echo $HTMLStructurePos;
$IsAuthenticatedPos=strpos( $result, ' [IsAuthenticated]' );
echo $IsAuthenticatedPos;
$result2 = substr($result, $HTMLStructurePos, $IsAuthenticatedPos);
echo "<pre>";
print_r($result2);
echo "</pre>";
} else {
echo "Not found";
}
but i get
Not found
in the out put.
I think this is a structure and I have to get the value with the pointer.But does anyone know how?
You get a nested object back from your Web-Service. Simplified as PHP code:
$result = (object)['Post_Added_Record_ByMenuIDResult' => (object)[
'HTMLStructure' => "ثبت انجام شد",
'IsAuthenticated' => 1,
//...
]];
The HTML can be accessed simply like this:
$html = $result->Post_Added_Record_ByMenuIDResult->HTMLStructure;
echo $html; // ثبت انجام شد
Just like HTMLStructure, you also get the values like IsAuthenticated.
i solved this problem by this code:
foreach ($result as $obj)
{
// Here you can access to every object value in the way that you want
$result2 = $obj->HTMLStructure;
}

json_decode foreach into table

Having Issues with nested arrays
I want to get the array title into the first cell of the table, having an issue articulated the nested foreach.
$content = file_get_contents("https://whattomine.com/asic.json");
$data = json_decode($content);
echo "coins";
foreach()
{
echo "<tr>";
echo "<th>".$coins->coinname."</th>";
echo "<th>".$coins->PoW."</th>";
echo "<th>".$coins->PoS."</th>";
echo "<th>".$coins->height."</th>";
echo "<th>".$coins->diff."</th>";
echo "<th>".$coins->supply."</th>";
echo "</tr>";
}
I've looked into the data and think I found what you want.
BUT you try to get values that are not in the data set.
The structure of that json is:
{"coins":
{"LitecoinCash":
{"id":231,"tag":"LCC",...}
},
...
}
So here's how to get that data:
$data = json_decode($content);
#var_dump($data);
echo "<table>";
foreach($data->coins as $title => $coin)
{
echo $title;
echo "<tr>";
echo "<th>".$title."</th>"; // the title as first cell
echo "<th>".$coin->id."</th>"; // added by me, coinname does not exist
echo "<th>".$coin->tag."</th>"; // added by me, PoW does not exist
#echo "<th>".$coin->PoS."</th>"; // all the others do not exist in the dataset.
#echo "<th>".$coin->height."</th>";
#echo "<th>".$coin->diff."</th>";
#echo "<th>".$coin->supply."</th>";
echo "</tr>";
}
echo "</table>";
// output:
// LitecoinCash 231 LCC
There is not keys you provided, but there is next keys:
example of item:
[LitecoinCash] => [
[id] => 231
[tag] => LCC
[algorithm] => SHA-256
[block_time] => 156.0
[block_reward] => 250
[block_reward24] => 250
[last_block] => 1460137
[difficulty] => 470292855.107
[difficulty24] => 396924068.28117
[nethash] => 12948028411711743
[exchange_rate] => 4.1E-6
[exchange_rate24] => 2.9135097493036E-6
[exchange_rate_vol] => 0.34130528
[exchange_rate_curr] => BTC
[market_cap] => $18,382,732.11
[estimated_rewards] => 149.54924
[estimated_rewards24] => 177.15706
[btc_revenue] => 0.00061315
[btc_revenue24] => 0.00072634
[profitability] => 102
[profitability24] => 121
[lagging] =>
[timestamp] => 1533048969
]
Which of them do you need?

Displaying Only the Items in the Cart?

So I need to display items that were added on the Vend Page and are now in the cart array over onto the cart page in a list
Array
(
[cart] => Array
(
[BRB] => 1
)
)
Here is my code for the cart page that I'm working on:
if (isset($_SESSION['cart'])) {
foreach ($vend as $vendID => $items) {
//if (array_search($vendID, $_SESSION['cart'])) {
echo "<article class ='cart' id='cart-$vendID'>";
echo "<h1 class = 'item-h1' id = 'h1'>{$items['title']}</h1>";
echo "<div class ='item-no'>";
echo "<p class = 'pro-id'><b>Product ID: </b>{$vendID}</p></div>";
echo "<div class ='img-div'>";
echo "<img src =../images/{$items['img']} alt='' height='196' width='200'></div>";
echo "<div class='pricing'>";
echo "<p><b>Price: $</b>{$items['price']}</p></div>";
echo "</article>";
//}
}
}
I commented out code that I attempted but didn't work. So I need an IF statement which says, If the vendID is in the cart array display it in the list.
Some help is appreciated here as I'm stuck.
Your cart should be as follows:
$cart = array(
[0] => Array
(
[item_id] => 1,
[title] => "your title",
[price] => 100,
[img] => "name of the file",
),
[1] => Array
(
[item_id] => 2,
[title] => "your title",
[price] => 200,
[img] => "name of the file",
)
);
And Then Try as follows:
if (isset($_SESSION['cart'])) {
foreach ($cart as $key => $items) { //$key = [0], [1] ....
echo "<article class ='cart' id='cart-$key'>";
echo "<h1 class = 'item-h1' id = 'h1'>".$items['title']."</h1>";
echo "<div class ='item-no'>";
echo "<p class = 'pro-id'><b>Product ID: </b>".$items['item_id']."</p></div>";
echo "<div class ='img-div'>";
echo "<img src =../images/".$items['img']." alt='' height='196' width='200'></div>";
echo "<div class='pricing'>";
echo "<p><b>Price: $</b>".$items['price']."</p></div>";
echo "</article>";
}
}
Mark, it accepted if it works.
Did you try in_array() ?
It checks if a value exists in an array.

PHRETS GetObject() returns array, need to extract URL

I'm performing a for loop to iterate through MLS listings. I'm able to get every bit of information I need but I can't seem to figure out how to extract the URL from the array I get.
Here's the array I get from my for loop:
PHRETS\Models\Object Object
(
[content_type:protected] => text/xml
[content_id:protected] => 9577056
[object_id:protected] => 1
[mime_version:protected] =>
[location:protected] => http://cdnparap100.paragonrels.com/ParagonImages/Property/P10/CAT/9577056/0/0/0/42ab28468ab0dfc6fd83dfb39e5dfff7/3/55ec2da6d4a32437d345d0992fae1851/9577056.JPG
[content_description:protected] =>
[content_sub_description:protected] =>
[content:protected] =>
[preferred:protected] =>
[error:protected] => PHRETS\Models\RETSError Object
(
[code:protected] => 0
[message:protected] =>
)
)
The following is the code I'm using to get that output. I'm just wondering if there's a way to do a trim or something to extract the URL so I can store it.
for ($i = 0; $i <= count($listID); $i++) {
$photo = $rets->GetObject('Property', 'Photo', $mls, '*', 1);
foreach ($photo as $image) {
echo "<pre>";
print_r($image);
echo "<br>";
echo "</pre>";
}
}
You mean like
foreach ($photo as $image) {
echo 'Location: ', $image->getLocation(), '<br>';
}
?
See https://github.com/troydavisson/PHRETS/blob/master/README.md#downloading-media-photos-images-documents-etc
The method is detailed here ~ https://github.com/troydavisson/PHRETS/blob/master/src/Models/Object.php#L109

How To Get Data from JSON Into Unordered List?

I have a JSON file that contain this:
"Menus": [{
"MenuId": "1",
"MenuName": "Perencanaan dan Pengadaan",
"MenuParent": "",
"MenuLink": ""
}, {
"MenuId": "1-1",
"MenuName": "RKA / DPA",
"MenuParent": "1",
"MenuLink": ""
}, {
"MenuId": "1-1-1",
"MenuName": "Daftar RKA / DPA",
"MenuParent": "1-1",
"MenuLink": "rkbu"
},
I want to put that data into unordered list dynamically. So the output I want is like this (with 3 level list):
Perencanaan dan Pengadaan
RKA / DPA
Daftar RKA / DPA
I have tried this code:
echo "<ul>";
foreach($get_data['Menus'] as $node){
if(strlen($node['MenuId']) == 1){
echo "<li>" . $node['MenuName'];
echo "</li>";
}
echo "<ul>";
if(strlen($node['MenuId']) == 3){
echo "<li>".$node['MenuName']."</li>";
}
if(strlen($node['MenuId']) == 5){
echo "<ul>";
echo "<li>".$node['MenuName']."</li>";
echo "</ul>";
}
echo "</ul>";
}
echo "</ul>";
But I find that it is not dynamic because it depends on string length. I've read that the best method is using recursive method. But I cannot find the recursive pattern of my JSON file. Can anybody help me find the solution? Thanks
I don't think it is possible to make recursive calls directly on your flat JSON data.
I suggest you first convert your flat data to a multidimensional array and afterwards recursively generate your menu.
I took parts of the code from here: Dynamically creating/inserting into an associative array in PHP
$get_data = array(
array(
"MenuId" => "1",
"MenuName" => "Perencanaan dan Pengadaan",
"MenuParent" => "",
"MenuLink" => ""
),
array(
"MenuId" => "1-1",
"MenuName" => "RKA / DPA",
"MenuParent" => "1",
"MenuLink" => ""
),
array(
"MenuId" => "1-1-1",
"MenuName" => "Daftar RKA / DPA",
"MenuParent" => "1-1",
"MenuLink" => "rkbu"
)
);
function insert_into(&$array, array $keys, $value) {
$last = array_pop($keys);
foreach($keys as $key) {
if(!array_key_exists($key, $array) ||
array_key_exists($key, $array) && !is_array($array[$key])) {
$array[$key]['items'] = array();
}
$array = &$array[$key]['items'];
}
$array[$last]['value'] = $value;
}
function create_menu($menuItems) {
$content = '<ul>';
foreach($menuItems as $item) {
$content .= '<li>' . $item['value'];
if(isset($item['items']) && count($item['items'])) {
$content .= create_menu($item['items']);
}
$content .= '</li>';
}
$content .= '</ul>';
return $content;
}
$menuItems = array();
foreach($get_data as $item) {
$levels = explode('-', $item['MenuId']);
insert_into($menuItems, $levels, $item['MenuName']);
}
print_r($menuItems);
print create_menu($menuItems);
DEMO: http://3v4l.org/dRK4f
Output:
Array (
[1] => Array (
[value] => Perencanaan dan Pengadaan
[items] => Array (
[1] => Array (
[value] => RKA / DPA
[items] => Array (
[1] => Array (
[value] => Daftar RKA / DPA
)
)
)
)
)
)
<ul>
<li>Perencanaan dan Pengadaan
<ul>
<li>RKA / DPA
<ul>
<li>Daftar RKA / DPA</li>
</ul>
</li>
</ul>
</li>
</ul>

Categories