Display image and description from plugin(redux) which is an array - php

I have this array which is inside the variable $cablecar_nhp. When I var_dump() the variable it give me this.
array(3) {
["last_tab"]=> string(0) ""
["media"]=> array(5) {
["url"]=> string(65) "http://sample.com/wp_cablecar/wp-content/uploads/2013/07/Koala.jpg"
["id"]=> string(2) "84"
["height"]=> string(3) "768"
["width"]=> string(4) "1024"
["thumbnail"]=> string(72) "http://sample.com/wp_cablecar/wp-content/uploads/2013/07/Koala-120x95.jpg"
}
["REDUX_imported"]=> bool(false)
}
What i want to do is to get and display the image. Can anybody help me ? I am working on Wordpress.

I'm one of the core devs of Redux. You can access your variable in question by expanding on what Valery said:
echo '<imv src="'.$cablecar_nhp['media']['url'].'">';
Or, do what pr1nc3 suggests above. ;)

You can try to do this:
echo '<img src = "'. $cablecar_nhp['url'] .'">';

extract($cablecar_nhp['media']);
<img src="$thumbnail" height="$height" width="$width" >

Related

PHP get specific value of a specific key in a multidimensional array

Say I have the following array (this comes from a var_dump):
($defaults = )array(3) {
["sitewide_typography_title"]=>
array(2) {
["font-family"]=>
string(16) "Playfair Display"
["variant"]=>
string(7) "regular"
}
["sitewide_typography_text"]=>
array(2) {
["font-family"]=>
string(6) "Roboto"
["variant"]=>
string(3) "300"
}
["sitewide_typography_btn"]=>
array(2) {
["font-family"]=>
string(6) "Roboto"
["variant"]=>
string(3) "300"
}
}
I guess this is an easy question, but I really can't find the answer. I think my googling skills failed me in this, but how do I get the font-family value for sitewide_typography_title?
Thanks a lot in advance!
It's simple
$defaults['sitewide_typography_title']['font-family'];
To echo it out like this
echo $defaults['sitewide_typography_title']['font-family'];
Should output
Playfair Display

How can I get the value of a key in this associative array

I have a CMS I am using that serializes their data in the database. I used the unserialize() function to convert the data into an associative array. Now I am having a hard time pulling the value of the image from the associative array:
This is the simple while loop I am using to loop through the rows:
while($row = mysql_fetch_assoc($query_models)){
$model_name = $row['ModelName'];
$model_thumbnail = unserialize($row['info']);
}
this is the Key and Value of the array I need to get the value of, so I can assign the correct thumbnail image to the respected person:
["1x_filename"]=> string(19) "00/83/83-set-1x.jpg"
The full array is below, and the key I am targeting is located more at the bottom of this array:
array(1) {
["thumbs"]=> array(2) {
[16]=> array(17) {
["id"]=> string(2) "82"
["1x_width"]=> string(3) "220"
["1x_height"]=> string(3) "330"
["2x_width"]=> string(3) "440"
["2x_height"]=> string(3) "660"
["3x_width"]=> string(3) "660"
["3x_height"]=> string(3) "990"
["4x_width"]=> string(3) "880"
["4x_height"]=> string(4) "1320"
["width"]=> string(3) "220"
["height"]=> string(3) "330"
["retinamode"]=> string(1) "1"
["filename"]=> string(10) "82-set.jpg"
["1x_filename"]=> string(19) "00/82/82-set-1x.jpg"
["2x_filename"]=> string(19) "00/82/82-set-2x.jpg"
["3x_filename"]=> string(19) "00/82/82-set-3x.jpg"
["4x_filename"]=> string(19) "00/82/82-set-4x.jpg"
}
[17]=> array(17) {
["id"]=> string(2) "83"
["1x_width"]=> string(3) "106"
["1x_height"]=> string(3) "150"
["2x_width"]=> string(3) "212"
["2x_height"]=> string(3) "300"
["3x_width"]=> string(3) "318"
["3x_height"]=> string(3) "450"
["4x_width"]=> string(3) "424"
["4x_height"]=> string(3) "600"
["width"]=> string(3) "106"
["height"]=> string(3) "150"
["retinamode"]=> string(1) "1"
["filename"]=> string(10) "83-set.jpg"
["1x_filename"]=> string(19) "00/83/83-set-1x.jpg"
["2x_filename"]=> string(19) "00/83/83-set-2x.jpg"
["3x_filename"]=> string(19) "00/83/83-set-3x.jpg"
["4x_filename"]=> string(19) "00/83/83-set-4x.jpg"
}
}
}
Any help would be greatly appreciated. Thanks!
Just like this :
$model_thumbnail = unserialize($row['info']);
$picturePath = $model_thumbnail['thumbs'][17]['1x_filename'];
picturePath will contain your images path
I would recommend you to use mysqli or an other database adapter in php, as mysql_ functions are depricated and even removed in never php versions. But according to your code, you could simply use a foreach loop to get your data.
Your results gives back some kind of data groups, I assume those are the user ids or something similar. It could also be the version or something like it. As I do not know that here are two possible ways
Get all:
while($row = mysql_fetch_assoc($query_models)){
$model_name = $row['ModelName'];
$model_thumbnail = unserialize($row['info']);
// echo all 1x_filename values from all given "ids"
foreach ($model_thumbnail['thumbs'] as $model_id => $model_values) {
print $model_values['1x_filename'];
}
}
Get only the latest id, in case those are for some kind of versioning:
while($row = mysql_fetch_assoc($query_models)){
$model_name = $row['ModelName'];
$model_thumbnail = unserialize($row['info']);
// sort array, so highest ID (assume-ably the newest)
krsort($model_thumbnail['thumbs']);
// get array entry
$firstEntry = reset($model_thumbnail['thumbs']);
print $firstEntry['1x_filename'];
}

Displaying items from my php array

Ive had a lot of help reading some of the questions asked on this site so I figured I would post a question of my own. I've recently been messing around with arrays and was wondering how I would go about displaying certain items from an array I have.
array(1) { [0]=> array(4) { ["kind"]=> string(25) "youtube#videoListResponse" ["etag"]=> string(57) ""blahblah"" ["pageInfo"]=> array(2) { ["totalResults"]=> int(1) ["resultsPerPage"]=> int(1) } ["items"]=> array(1) { [0]=> array(5) { ["kind"]=> string(13) "youtube#video" ["etag"]=> string(57) ""blahblah"" ["id"]=> string(11) "XS6ysDFTbLU" ["snippet"]=> array(9) { ["publishedAt"]=> string(24) "2014-08-15T17:22:04.000Z" ["channelId"]=> string(24) "UCnEiGCE13SUI7ZvojTAVBKw" ["title"]=> string(35) "Bill Gates ALS Ice Bucket Challenge" ["description"]=> string(212) "Bill Gates accepts Mark Zuckerberg’s ALS Ice Bucket Challenge and nominates Elon Musk, Ryan Seacrest and Chris Anderson from TED to participate and raise awareness for ALS, also known as Lou Gehrig’s Disease." ["thumbnails"]=> array(5) { ["default"]=> array(3) { ["url"]=> string(46) "https://i.ytimg.com/vi/XS6ysDFTbLU/default.jpg" ["width"]=> int(120) ["height"]=> int(90) } ["medium"]=> array(3) { ["url"]=> string(48) "https://i.ytimg.com/vi/XS6ysDFTbLU/mqdefault.jpg" ["width"]=> int(320) ["height"]=> int(180) } ["high"]=> array(3) { ["url"]=> string(48) "https://i.ytimg.com/vi/XS6ysDFTbLU/hqdefault.jpg" ["width"]=> int(480) ["height"]=> int(360) } ["standard"]=> array(3) { ["url"]=> string(48) "https://i.ytimg.com/vi/XS6ysDFTbLU/sddefault.jpg" ["width"]=> int(640) ["height"]=> int(480) } ["maxres"]=> array(3) { ["url"]=> string(52) "https://i.ytimg.com/vi/XS6ysDFTbLU/maxresdefault.jpg" ["width"]=> int(1280) ["height"]=> int(720) } } ["channelTitle"]=> string(13) "thegatesnotes" ["categoryId"]=> string(2) "29" ["liveBroadcastContent"]=> string(4) "none" ["localized"]=> array(2) { ["title"]=> string(35) "Bill Gates ALS Ice Bucket Challenge" ["description"]=> string(212) "Bill Gates accepts Mark Zuckerberg’s ALS Ice Bucket Challenge and nominates Elon Musk, Ryan Seacrest and Chris Anderson from TED to participate and raise awareness for ALS, also known as Lou Gehrig’s Disease." } } ["statistics"]=> array(5) { ["viewCount"]=> string(8) "23231956" ["likeCount"]=> string(6) "206532" ["dislikeCount"]=> string(4) "4471" ["favoriteCount"]=> string(1) "0" ["commentCount"]=> string(5) "14548" } } } } }
so this is the array i'm trying to extract values from. Could someone maybe show me how to display the localized title, default thumbnail and viewcount with php. I think from there I can manage to get the rest figured out. Any help would be appreciated. Thanks
P.S.
I've tried to use the below code with no luck.
$MYarray = array($ARRAY_Data);
echo $MYarray['items'][0]['statistics']['viewCount'];
$ARRAY_Data holds the array I posted at the top.
It looks like the thing that's causing you problems is this:
$MYarray = array($ARRAY_Data);
That just adds another array around your original array, which doesn't seem like it should be necessary, and based on your var_dump output, if you hadn't done that, in the next line
echo $MYarray['items'][0]['statistics']['viewCount'];
you're actually already using the correct array keys to get you the value you want. So just skip the $MYarray = array($ARRAY_Data); and use the same keys on the original array:
echo $ARRAY_Data['items'][0]['statistics']['viewCount'];

PHP CodeIgniter Foreach Returning Incorrect Data

Hello awesome programmers!
I am so sorry for the the novice question, however, I am having trouble finding a solution to my problem. I am attempting to run a for each loop through my array passed from my controller, however, the data being outputted is not the same as when I run a var_dump($array). I am thinking perhaps that I need to iterate through this object maybe? However, when I attempt to do so, I get a non-object error.
Controller:
$data['user_details'] = $this->ion_auth->user()->row();
View:
var_dump($user_details);
foreach($user_details as $item){
echo $item['email'];
}
The output of this is : "21nfn4111NR12" but should be roger#peterson.net!
I have also tried the object form:
var_dump($user_details);
foreach($user_details as $item){
echo $item->email;
}
However, it results in error trying to get property of non-object!
When I run the var dump I get the following:
object(stdClass)#21 (17) {
["id"]=>
string(1) "2"
["ip_address"]=>
string(14) "119.132.127.01"
["username"]=>
string(12) "roger petereson"
["password"]=>
string(40) "fdZxF/RQo4nZKmbA5XQlwefbc8f8e5c74899c3d0"
["salt"]=>
NULL
["email"]=>
string(19) "roger#peterson.net"
["activation_code"]=>
NULL
["forgotten_password_code"]=>
NULL
["forgotten_password_time"]=>
NULL
["remember_code"]=>
string(22) "44hjOlloLTIrkSrjSBVNie"
["created_on"]=>
string(10) "1404939094"
["last_login"]=>
string(10) "1405099607"
["active"]=>
string(1) "1"
["first_name"]=>
string(6) "Roger"
["last_name"]=>
string(5) "Peterson"
["is_owner"]=>
string(1) "1"
["user_id"]=>
string(1) "2"
}
The following line:
$this->ion_auth->user()->row();
returns an object not an array (check your var_dump output), so you just need to
echo $user_details->email;

How do I get the data out of this array? Single sign on

I have implemented a Single Sign on function using Janrain. It outputs this data (amongst other data). Is it possible to break this down and extract only the displayName for example so that I may place it in a variable?
auth_info:
array(3) {
["stat"]=>
string(2) "ok"
["profile"]=>
array(10) {
["providerName"]=>
string(8) "Facebook"
["identifier"]=>
string(48) "removed"
["preferredUsername"]=>
string(10) "OllieJones"
["displayName"]=>
string(11) "Ollie Jones"
["name"]=>
array(3) {
["formatted"]=>
string(11) "Ollie Jones"
["givenName"]=>
string(5) "Ollie"
["familyName"]=>
string(5) "Jones"
}
Here is the script that creates it and where I would like to define the variable https://github.com/janrain/Janrain-Sample-Code/blob/master/php/rpx-token-url.php
Many Thanks
Try $auth_info['profile']['displayName']

Categories