I've recently come across the php function exif_read_data - which is pretty awesome. I'm using it on my photography site, and while it works pretty well, I'm struggling to work out why ApertureFNumber isn't working. The code I'm using is:
$exif_data = exif_read_data($image[0]);
echo $exif_data['Model'];
echo $exif_data['ExposureTime'];
echo $exif_data['FNumber'];
echo $exif_data['ApertureFNumber'];
echo $exif_data['ISOSpeedRatings'];
echo $exif_data['DateTime'];
(styling removed)
I used FNumber as well as ApertureFNumber for testing because FNumber works, while ApertureFNumberjust returns blank. All the other fields work fine.
I did a var_dump of $exif_data - and this is what I get (the abridged version):
["ApertureFNumber"]=> string(5) "f/3.5"
["FNumber"]=> string(5) "35/10"
What have I missed that FNumber works, but ApertureFNumber doesn't?
--
EDIT - Complete var_dump added as requested
array(52) { ["FileName"]=> string(18) "MYD-67-900x602.jpg" ["FileDateTime"]=> int(0) ["FileSize"]=> int(123278) ["FileType"]=> int(2) ["MimeType"]=> string(10) "image/jpeg" ["SectionsFound"]=> string(30) "ANY_TAG, IFD0, THUMBNAIL, EXIF" ["COMPUTED"]=> array(9) { ["html"]=> string(24) "width="900" height="602"" ["Height"]=> int(602) ["Width"]=> int(900) ["IsColor"]=> int(1) ["ByteOrderMotorola"]=> int(0) ["ApertureFNumber"]=> string(5) "f/3.5" ["FocusDistance"]=> string(14) "4294967296.00m" ["Thumbnail.FileType"]=> int(2) ["Thumbnail.MimeType"]=> string(10) "image/jpeg" } ["Make"]=> string(17) "NIKON CORPORATION" ["Model"]=> string(9) "NIKON D60" ["XResolution"]=> string(5) "200/1" ["YResolution"]=> string(5) "200/1" ["ResolutionUnit"]=> int(2) ["Software"]=> string(41) "Adobe Photoshop Lightroom 4.4 (Macintosh)" ["DateTime"]=> string(19) "2013:07:06 10:07:40" ["Exif_IFD_Pointer"]=> int(216) ["THUMBNAIL"]=> array(6) { ["Compression"]=> int(6) ["XResolution"]=> string(5) "200/1" ["YResolution"]=> string(5) "200/1" ["ResolutionUnit"]=> int(2) ["JPEGInterchangeFormat"]=> int(932) ["JPEGInterchangeFormatLength"]=> int(8995) } ["ExposureTime"]=> string(5) "1/800" ["FNumber"]=> string(5) "35/10" ["ExposureProgram"]=> int(1) ["ISOSpeedRatings"]=> int(100) ["ExifVersion"]=> string(4) "0230" ["DateTimeOriginal"]=> string(19) "2008:10:30 16:04:34" ["DateTimeDigitized"]=> string(19) "2008:10:30 16:04:34" ["ShutterSpeedValue"]=> string(15) "9643856/1000000" ["ApertureValue"]=> string(13) "361471/100000" ["ExposureBiasValue"]=> string(3) "0/6" ["MaxApertureValue"]=> string(5) "36/10" ["SubjectDistance"]=> string(4) "-1/1" ["MeteringMode"]=> int(5) ["LightSource"]=> int(0) ["Flash"]=> int(0) ["FocalLength"]=> string(4) "18/1" ["SubSecTimeOriginal"]=> string(2) "50" ["SubSecTimeDigitized"]=> string(2) "50" ["SensingMethod"]=> int(2) ["FileSource"]=> string(1) "" ["SceneType"]=> string(1) "" ["CFAPattern"]=> string(8) "" ["CustomRendered"]=> int(0) ["ExposureMode"]=> int(1) ["WhiteBalance"]=> int(0) ["DigitalZoomRatio"]=> string(3) "1/1" ["FocalLengthIn35mmFilm"]=> int(27) ["SceneCaptureType"]=> int(0) ["GainControl"]=> int(0) ["Contrast"]=> int(0) ["Saturation"]=> int(0) ["Sharpness"]=> int(0) ["SubjectDistanceRange"]=> int(0) ["UndefinedTag:0xA431"]=> string(7) "6265825" ["UndefinedTag:0xA432"]=> array(4) { [0]=> string(4) "18/1" [1]=> string(4) "55/1" [2]=> string(5) "35/10" [3]=> string(5) "56/10" } ["UndefinedTag:0xA434"]=> string(22) "18.0-55.0 mm f/3.5-5.6" }
Try This:
$exif = exif_read_data($image[0]);
foreach($exif as $exif_data){
echo $exif_data['Model']."<br/>";
echo $exif_data['ExposureTime']."<br/>";
echo $exif_data['FNumber']."<br/>";
echo "ApertureFNumber is:" .$exif_data['ApertureFNumber']."<br/>";
echo $exif_data['ISOSpeedRatings']."<br/>";
echo $exif_data['DateTime']."<br/>";
}
So, I got this figured out now - and thought you might like to see the answer.
The var_dump was giving the data ["ApertureFNumber"]=> string(5) "f/3.5", but wasn't really getting me anywhere, so instead I used print_r($exif_data). That printed out a whole load of useful data including the following:
[COMPUTED] => Array
(
[html] => width="1000" height="667"
[Height] => 667
[Width] => 1000
[IsColor] => 1
[ByteOrderMotorola] => 0
[ApertureFNumber] => f/3.5
[Thumbnail.FileType] => 2
[Thumbnail.MimeType] => image/jpeg
[Thumbnail.Height] => 171
[Thumbnail.Width] => 256
)
So, to echo out the needed ApertureFNumber I simply used echo $exif['COMPUTED']['ApertureFNumber']; It also works for any of the information in the printed array.
Hopefully this helps someone else in the future.
Related
I'm trying to fetch the values within the fruit object and within the options object. You can see there are a list of items within it 100% Orange Juice, Apple, Pear, Pineapple and etc. How can loop through a very nested object in order to fetch those values.
I've tried using foreach to fetch those items but it seems I'm doing it incorrectly.
$fruitsArray = $product->get_attributes('');
foreach ( $fruitsValue as $fruitsArray ) {
echo $fruitsValue
}
<?php var_dump($product->get_attributes('')); ?>
array(2) {
["size"]=>
object(WC_Product_Attribute)#2724 (1) {
["data":protected]=>
array(6) {
["id"]=>
int(0)
["name"]=>
string(4) "Size"
["options"]=>
array(3) {
[0]=>
string(6) "400 ml"
[1]=>
string(2) "1L"
[2]=>
string(2) "2L"
}
["position"]=>
int(0)
["visible"]=>
bool(true)
["variation"]=>
bool(false)
}
}
["fruit"]=>
object(WC_Product_Attribute)#2723 (1) {
["data":protected]=>
array(6) {
["id"]=>
int(0)
["name"]=>
string(5) "Fruit"
["options"]=>
array(8) {
[0]=>
string(17) "100% Orange Juice"
[1]=>
string(5) "Apple"
[2]=>
string(4) "Pear"
[3]=>
string(9) "Pineapple"
[4]=>
string(12) "Passionfruit"
[5]=>
string(15) "Red Dragonfruit"
[6]=>
string(13) "Baobab Powder"
[7]=>
string(17) "Grapeseed Extract"
}
["position"]=>
int(1)
["visible"]=>
bool(true)
["variation"]=>
bool(false)
}
}
}
I have small problem, I can't get info from an array.
This is outcome when I var_dump variable.
array(1) {
["server"]=> array(34) {
["dedicated"]=> string(1) "d"
["game_descr"]=> string(14) "Counter-Strike"
["game_dir"]=> string(7) "cstrike"
["gq_address"]=> string(13) "185.119.89.91"
["gq_dedicated"]=> string(1) "d"
["gq_gametype"]=> string(14) "Counter-Strike"
["gq_hostname"]=> string(26) "Assassin'S CSDM [de_dust2]"
["gq_joinlink"]=> string(36) "steam://connect/185.119.89.91:27031/"
["gq_mapname"]=> string(8) "de_dust2"
["gq_maxplayers"]=> int(32)
["gq_mod"]=> string(7) "cstrike"
["gq_name"]=> string(18) "Counter-Strike 1.6"
["gq_numplayers"]=> int(32)
["gq_online"]=> bool(true)
["gq_password"]=> int(0)
["gq_port_client"]=> int(27031)
["gq_port_query"]=> int(27031)
["gq_protocol"]=> string(6) "source"
["gq_transport"]=> string(3) "udp"
["gq_type"]=> string(4) "cs16"
["hostname"]=> string(26) "Assassin'S CSDM [de_dust2]"
["map"]=> string(8) "de_dust2"
["max_players"]=> int(32)
["num_bots"]=> int(0)
["num_players"]=> int(32)
["os"]=> string(1) "l"
["password"]=> int(0)
["players"]=> array(0) { }
["port"]=> int(27031)
["protocol"]=> int(48)
["secure"]=> int(1)
["steamappid"]=> int(10)
["teams"]=> array(0) { }
["version"]=> string(13) "1.1.2.7/Stdio"
}
}
How to get hostname for example?
I tried like $info['hostname'], $info[0]['hostname']; But nothing works, why?
array(1) { ... }
The array has one thing in it.
["server"]=> array(34) { ... }
… which is another array with 34 things in it.
You are ignoring the outer array. You need to get the inner array and then access the item you want from that.
$info['server']['hostname']
I want to get term_id values from this array without any loops or foreach.
I need it To be:
First Term id is :
Second Term id is :
I tried using echo $term[0]->term_id; but it is not working
Here is My var_dump result:
array(2) {
[0]=>
object(WP_Term)#4046 (10) {
["term_id"]=>
int(72)
["name"]=>
string(14) "samsung"
["slug"]=>
string(91) "samsung"
["term_group"]=>
int(0)
["term_taxonomy_id"]=>
int(72)
["taxonomy"]=>
string(11) "product_cat"
["description"]=>
string(0) ""
["parent"]=>
int(63)
["count"]=>
int(5)
["filter"]=>
string(3) "raw"
}
[1]=>
object(WP_Term)#4045 (10) {
["term_id"]=>
int(64)
["name"]=>
string(15) "onclikck"
["slug"]=>
string(8) "onclikck"
["term_group"]=>
int(0)
["term_taxonomy_id"]=>
int(64)
["taxonomy"]=>
string(11) "product_cat"
["description"]=>
string(92) "Description"
["parent"]=>
int(63)
["count"]=>
int(3)
["filter"]=>
string(3) "raw"
}
}
Try it like this:
$term[0]['term_id']
I'm using cakephp 2.x and I would like to get certain element as field from my model. the problem is with my structure. If I use find all then I recieve this:
array(9) {
[0]=> ...
[1]=>
array(7) {
["Person"]=>
array(18) {
["id"]=>
int(2)
["imie"]=>
string(6) "STEFAN"
["nazwisko"]=>
string(8) "ŚMIAŁY"
["tel"]=>
string(13) "+55 648989748"
["mob"]=>
string(13) "+87 489747489"
["email"]=>
string(25) "HSDJKAHSDJK#HSDFJASHF.CIJ"
["tytul_naukowy"]=>
string(7) "TEZ NIE"
["data_od"]=>
string(10) "2017-02-16"
["data_do"]=>
NULL
["object_id"]=>
int(-1)
["object_type_id"]=>
int(2)
["duty_id"]=>
int(28)
["created"]=>
string(22) "2017-02-16 13:22:32+01"
["modified"]=>
string(22) "2017-02-16 13:22:32+01"
["deleted"]=>
int(0)
["additional_email"]=>
string(17) "UDIHAS#HFSDKFH.OK"
["description"]=>
string(4) "OPIS"
["displayName"]=>
string(15) "STEFAN ŚMIAŁY"
}
["Duty"]=>
array(3) {
["id"]=>
int(28)
["nazwa"]=>
string(20) "KOORDYNATOR RECEPCJI"
["atrybut"]=>
string(1) "W"
}
["ObjectType"]=>
array(3) {
["id"]=>
int(2)
["nazwa"]=>
string(4) "Obks"
["model"]=>
string(3) "Obk"
}
["Cro"]=>
array(12) {
["id"]=>
NULL
["created"]=>
NULL
["nazwa"]=>
NULL
["tel"]=>
NULL
["fax"]=>
NULL
["email"]=>
NULL
["www"]=>
NULL
["modified"]=>
NULL
["deleted"]=>
NULL
["cro_type_id"]=>
NULL
["displayName"]=>
NULL
["objectTypeIdWithId"]=>
NULL
}
["Attachment"]=>
array(0) {
}
["Specialization"]=>
array(0) {
}
["Obk"]=>
array(1) {
[0]=>
array(13) {
["id"]=>
int(2)
["nazwa"]=>
string(10) "OBK Z ID 2"
["tel"]=>
string(13) "+48 123456890"
["fax"]=>
string(13) "+48 123456789"
["email"]=>
string(15) "EMAIL#EMAIL.COM"
["www"]=>
string(11) "WWW.WWW.WWW"
["modified"]=>
string(22) "2017-03-20 15:11:31+01"
["created"]=>
string(22) "2014-05-12 21:50:17+02"
["deleted"]=>
int(0)
["local_order"]=>
int(3)
["displayName"]=>
string(10) "OBK Z ID 2"
["objectTypeIdWithId"]=>
string(3) "2_2"
["PeopleObk"]=>
array(3) {
["id"]=>
int(1)
["person_id"]=>
int(2)
["obk_id"]=>
int(2)
}
}
}
}
[2]=>
array(7) {
["Person"]=>
array(18) {
["id"]=>
int(3)
["imie"]=>
string(5) "KAMIL"
["nazwisko"]=>
string(10) "STEFAŃSKI"
["tel"]=>
string(13) "+23 123123123"
["mob"]=>
string(13) "+21 412312312"
["email"]=>
string(16) "ASDASD#SDFDSF.LS"
["tytul_naukowy"]=>
string(3) "NIE"
["data_od"]=>
string(10) "2017-02-22"
["data_do"]=>
NULL
["object_id"]=>
int(-1)
["object_type_id"]=>
int(2)
["duty_id"]=>
int(26)
["created"]=>
string(22) "2017-02-22 16:14:32+01"
["modified"]=>
string(22) "2017-02-22 16:14:32+01"
["deleted"]=>
int(0)
["additional_email"]=>
string(22) "ADAM.2313#WEBIMPULS.PL"
["description"]=>
string(4) "TEST"
["displayName"]=>
string(16) "KAMIL STEFAŃSKI"
}
["Duty"]=>
array(3) {
["id"]=>
int(26)
["nazwa"]=>
string(41) "KOORDYNATOR OŚRODKÓW BADAŃ KLINICZNYCH"
["atrybut"]=>
string(1) "W"
}
["ObjectType"]=>
array(3) {
["id"]=>
int(2)
["nazwa"]=>
string(4) "Obks"
["model"]=>
string(3) "Obk"
}
["Cro"]=>
array(12) {
["id"]=>
NULL
["created"]=>
NULL
["nazwa"]=>
NULL
["tel"]=>
NULL
["fax"]=>
NULL
["email"]=>
NULL
["www"]=>
NULL
["modified"]=>
NULL
["deleted"]=>
NULL
["cro_type_id"]=>
NULL
["displayName"]=>
NULL
["objectTypeIdWithId"]=>
NULL
}
["Attachment"]=>
array(0) {
}
["Specialization"]=>
array(0) {
}
["Obk"]=>
array(1) {
[0]=>
array(13) {
["id"]=>
int(3)
["nazwa"]=>
string(10) "OBK Z ID 3"
["tel"]=>
string(13) "+48 123456890"
["fax"]=>
string(13) "+48 123456789"
["email"]=>
string(15) "EMAIL#EMAIL.COM"
["www"]=>
string(11) "WWW.WWW.WWW"
["modified"]=>
string(22) "2017-03-20 10:45:24+01"
["created"]=>
string(22) "2014-05-16 09:09:33+02"
["deleted"]=>
int(0)
["local_order"]=>
int(1)
["displayName"]=>
string(10) "OBK Z ID 3"
["objectTypeIdWithId"]=>
string(3) "2_3"
["PeopleObk"]=>
array(3) {
["id"]=>
int(2)
["person_id"]=>
int(3)
["obk_id"]=>
int(3)
}
}
}
}
And I want just to retrieve Person.id, Person.displayName and Obk.0.id. The two first are no problem, but wheneve I try to get Obk.0.id I'm getting error: SQLSTATE[42P01]: Undefined table: 7 ERROR: missing FROM for Table Obk.
How can I get something like that? I want to set the value in codition later, but it block my work.
In CakePHP 2 you can specify the fields you want returned by a find() query using the fields option like:-
$this->Foo->find('all', [
'fields' => ['Foo.id', 'Foo.name']
]);
This also works with contained models that have a belongsTo or hasOne relationship:-
$this->Foo->find('all', [
'fields' => ['Foo.id', 'Foo.name', 'Bar.name'],
'contain' => ['Bar']
]);
However, if the contained model is a hasMany or HABTM relationship you need to specify the fields of that model on the contain:-
$this->Foo->find('all', [
'fields' => ['Foo.id', 'Foo.name'],
'contain' => [
'Bar' => ['fields' => 'Bar.name']
]
]);
This is because CakePHP will be performing multiple SQL queries, so the contain needs to have the parameters for the query being run for the relevant model.
I have a newbie question here, but I'm really stucked. I have a multidimensional array that comes from a SELECT from a database, what I need is pretty simple, I'm doing a graphic where contains the number of results of each column of every user specified.
Heres some code to clarify your minds:
try {
$pdo = new PDO('mysql:host=***; dbname=**;charset=utf8;', '***', '**');
}catch(PDOException $err){
echo "Erro:\n".$err->getMessage();
}
$sql = "SELECT * FROM results
WHERE ra like '****'";
$statement = $pdo->prepare($sql);
$statement->execute();
$result = $statement->fetchAll();
$resultPgto = array_column($result, 'indicado_pgto');
print_r($resultadoPgto);
This returns me this array:
array(3) {
[0]=>
string(18) "Indicacao Invalida"
[1]=>
string(3) "Nao"
[2]=>
string(3) "Nao"
}
I need to count the results that are equal to Sim AND it should returns me 0 but instead when I do something like print_r($resultadoPgto == 'Sim'); it returns '1'...
Other funny fact is, when I try to return results that are equal to Nao (theres 2 there) it returns me 0 or 1...
What I'm missing here? Can someone please help?
EDIT 1 :
Counting the result itself will return the number of keys the array has.
Here is the full Result to your understanding.
array(3) {
[0]=>
array(22) {
["dsadsad"]=>
string(7) "***"
[0]=>
string(7) "****"
["nome_aluno"]=>
string(25) "lore"
[1]=>
string(25) "ipsum"
["nome_indicado"]=>
string(25) "lore"
[2]=>
string(25) "ipsum"
["indicado_inscrito"]=>
string(18) "Indica��o Inv�lida"
[3]=>
string(18) "Indica��o Inv�lida"
["indicado_confirmado"]=>
string(18) "Indica��o Inv�lida"
[4]=>
string(18) "Indica��o Inv�lida"
["indicado_presente"]=>
string(18) "Indica��o Inv�lida"
[5]=>
string(18) "Indica��o Inv�lida"
["indicado_aprovado"]=>
string(18) "Indica��o Inv�lida"
[6]=>
string(18) "Indica��o Inv�lida"
["indicado_matriculado"]=>
string(18) "Indica��o Inv�lida"
[7]=>
string(18) "Indica��o Inv�lida"
["indicado_pgto"]=>
string(18) "Indicacao Invalida"
[8]=>
string(18) "Indicacao Invalida"
["validacao_indicacao"]=>
string(3) "N�o"
[9]=>
string(3) "N�o"
["validacao_desconto"]=>
string(3) "N�o"
[10]=>
string(3) "N�o"
}
[1]=>
array(22) {
["dsdsdasda"]=>
string(7) "***"
[0]=>
string(7) "***"
["nome_aluno"]=>
string(25) "lore"
[1]=>
string(25) "ipsum"
["nome_indicado"]=>
string(23) "lore"
[2]=>
string(23) "ipsum"
["indicado_inscrito"]=>
string(3) "Sim"
[3]=>
string(3) "Sim"
["indicado_confirmado"]=>
string(3) "N�o"
[4]=>
string(3) "N�o"
["indicado_presente"]=>
string(9) "EM ABERTO"
[5]=>
string(9) "EM ABERTO"
["indicado_aprovado"]=>
string(9) "EM ABERTO"
[6]=>
string(9) "EM ABERTO"
["indicado_matriculado"]=>
string(3) "N�o"
[7]=>
string(3) "N�o"
["indicado_pgto"]=>
string(3) "Nao"
[8]=>
string(3) "Nao"
["validacao_indicacao"]=>
string(3) "Sim"
[9]=>
string(3) "Sim"
["validacao_desconto"]=>
string(3) "N�o"
[10]=>
string(3) "N�o"
}
[2]=>
array(22) {
["asdasdsad"]=>
string(7) "***"
[0]=>
string(7) "***"
["nome_aluno"]=>
string(25) "lore"
[1]=>
string(25) "ipsum"
["nome_indicado"]=>
string(15) "lore"
[2]=>
string(15) "ipsum"
["indicado_inscrito"]=>
string(3) "Sim"
[3]=>
string(3) "Sim"
["indicado_confirmado"]=>
string(3) "N�o"
[4]=>
string(3) "N�o"
["indicado_presente"]=>
string(9) "EM ABERTO"
[5]=>
string(9) "EM ABERTO"
["indicado_aprovado"]=>
string(9) "EM ABERTO"
[6]=>
string(9) "EM ABERTO"
["indicado_matriculado"]=>
string(3) "N�o"
[7]=>
string(3) "N�o"
["indicado_pgto"]=>
string(3) "Nao"
[8]=>
string(3) "Nao"
["validacao_indicacao"]=>
string(3) "Sim"
[9]=>
string(3) "Sim"
["validacao_desconto"]=>
string(3) "N�o"
[10]=>
string(3) "N�o"
}
}
The only field I need information is "indicado_pgto", thats why I did the array_column()
What I really need is compare each value and count them, to return me any position that have the string 'Sim' on it, and even if don't have any 'Sim' string on it, it returns me 1
If you have this array after using array_column() on the SQL results, then the assumption is that your target array looks like this:
array(3) {
[0]=>
string(18) "Indicacao Invalida"
[1]=>
string(3) "Nao"
[2]=>
string(3) "Nao"
}
If so, then you should be able to do something simple like this?
<?php
$counter = 0;
foreach ($resultadoPgto as $result) {
if ($result === 'Nao') {
$counter++;
}
}
print_r($counter);
Note that I used the triple equality operator === instead of the double equality operator==.
The weird behaviour you are experiencing with your print_r($resultadoPgto == 'Sim') returning '1' or '0' could be an side effect of using the double equality operator since it does not take the data type in consideration when evaluating the expression.
This will count the occurances of any field in an array that match a specified value.
function count_occ($array, $field, $content) {
$cnt = 0;
foreach( $array as $a) {
if ($a[$field] = $content) { $cnt++; }
}
return $cnt;
}
echo count_occ($result, 'indicado_pgto', 'Sim');