Display a data from an array - php

I just want to ask how to display the data from an array like this? Here's the link
This is my first time seeing an array like this long and I am confused. I tried getting the data from the cart_message and I get an array as a result. I'm sure this is the wrong format to get it. I am a newbie when it comes to this.
$messages['cart_message'];
Update:
Here's what I am trying to do.
I am trying to display the string on the cart_message
I want to display the text on the cart_message on the side cart template. So, to do that, I thought it will display if I use this filter
$yith_message = apply_filters( 'yith_ywpar_panel_messages_options', $messages);
echo '<pre>'; var_dump($yith_message); echo '</pre>';
The result is Null

Try:
var_export($messages);
More info: var_export

Related

Grab, filter and show this data in PHP

This is example what I mean:
I wanna grab result from this url web1.com/do.php?id=45944
Example output:
"pk":"bn564vc3b5yvct5byvc45bv","1b":129,"isvalid":true,"referrer":true,"mobile":true
Then, I will show data result on other site web2.com/show.php
But I just wanna see data value "pk", "1b" and "isvalid". I don't need "referrer" and "mobile" data.
So, when I access web2.com/show.php, it just show data like this:
bn564vc3b5yvct5byvc45bv 129 true
file_get_contents web1.com/do.php?id=45944
Grab this result "pk":"bn564vc3b5yvct5byvc45bv","1b":129,"isvalid":true,"referrer":true,"mobile":true
Filter and show value "pk", "1b" and "isvalid" on web2.com/show.php
So, can you help me with simple php code/script?
Sorry if you don't understand because my english.
Is this source providing JSON-formatted data? That is, with { }'s around it?
If so, use PHP's built in json_decode function. (Man page at http://php.net/manual/en/function.json-decode.php) It will parse the JSON data for you and return an associative array. For example
$your_JSON_data = '{"pk":"bn564vc3b5yvct5byvc45bv","1b":129,"isvalid":true,"referrer":true,"mobile":true}';
$your_array = json_decode($your_JSON_data);
echo $your_array['pk'] . ' ';
echo $your_array['1b'] . ' ';
echo $your_array['isvalid'];
If, for some reason, there are no JSON-style curly braces around your data, you can append them.... for example,
$proper_JSON = "{$bad_json_data}";
however, if that's the case, I'd wonder why it wasn't properly formatted in the first place. In that case it may be safer to use the PHP explode function (http://php.net/manual/en/function.explode.php)

fetch array from a given url in php

i have a url.. eg http://www.example.com/index.php?rou=feed/web_api/categories&key=4&parent=0&level=10
when i hit the link simply on browser it displays a long list of multidimensional array.
I want to know that is it possible to store the url in a variable, something like this
$link=http://www.example.com/index.php?rou=feed/web_api/categories&key=4&parent=0&level=10
And then display the array in it as
echo '<pre>';
print_r($link);
echo '</pre>';
and then fetch the values from the array
I tried doing so but it displayed only a blank screen. Not sure if i am going on the right track. can anyone guide me
I think you are looking for one of these:
$data = file_get_contents('http://example.com/data.php');
This will fetch the raw data from the specified URL, and store the contents to the variable.
You may then need to implement your own code to actually parse the raw data, depending on your encoding type.

PHP PDO Fetching Results

I'm trying to simply echo results out on the screen from my database. I'm quite new with PDO, and I've been searching on this site for an answer that works, but have found none so far.
$results = $MyConnection->prepare("SELECT Antwoord1, Antwoord2, Antwoord3 FROM CCOpendag ");
$results->execute();
$foundResults = $results->fetchAll(PDO::FETCH_ASSOC);
echo $foundResults;
This piece of code simply echoes out 'Array'. What I want to achieve is that I get the results from these 3 columns and display them on the screen.
If somebody could help me out, that would be amazing.
print_r($foundResults) or var_dump($foundResults)
It shows "Array" because you need to iterate over the results, and not simply just echo it out. Use var_dump or print_r and you should see the array; you can then loop out the results as you wish - var_dump will just show you the whole array.
$foundResults is an array with all the records .
You can view the array by using print_r($foundResults).
Or it will be better if you use a loop to read each rows
while($foundResults=$results>fetch(PDO::FETCH_ASSOC)) {
echo $foundResults['Antwoord1'].$foundResults['Antwoord2'];
}

php json decode blank page

Hello I want to decode json. My code below:
<?php
$json = '{"response":{"count":1,"items":[{"id":165983743,"owner_id":170785079,"title":"Ke$ha - Blow","duration":253,"description":"","date":1379017507,"views":1,"comments":0,"photo_130":"http:\/\/cs518121.vk.me\/u170785079\/video\/s_5e5f6f2c.jpg","photo_320":"http:\/\/cs518121.vk.me\/u170785079\/video\/l_dd4ec237.jpg","files":{"mp4_240":"http:\/\/cs518121v4.vk.me\/u170785079\/videos\/500770e51c.240.mp4","mp4_360":"http:\/\/cs518121v4.vk.me\/u170785079\/videos\/500770e51c.360.mp4","mp4_480":"http:\/\/cs1-46v4.vk.me\/p13\/483502b20c4f.480.mp4","mp4_720":"http:\/\/cs518121v4.vk.me\/u170785079\/videos\/500770e51c.720.mp4"},"player":"http:\/\/vk.com\/video_ext.php?oid=170785079&id=165983743&hash=1e417a266e9a3f00"}]}}';
$obj = json_decode($json);
print_r ($obj);
print $obj->{'response'}->{'items'}->{'files'}->{'mp4_240'};
But I get a blank page
print_r should actually print something - your json is correct.
You should do it like this:
print $obj->response->items[0]->files->mp4_240;
Here's a code working on ideone: http://ideone.com/4xXfOl
EDIT: Please whoever downvoted these answers, explain why you do so in comments...
at first u must enable display errors at yours php interpreter
ini_set('display_errors',1);
error_reporting(E_ALL);
and then u have to read more intently the structure of json which u want to travers, the
items as an array, actually the object keys says it to you: the plural form of item
so the solve is:
print $obj->{'response'}->{'items'}[0]->{'files'}->{'mp4_240'};
of course I dislike such syntax, it would be better using
print $obj->response->items[0]->files->mp4_240;
use $obj->{'prop_name'} form when the programm selects accessing attributes dynamicly
I think you need this
echo $obj->response->items[0]->files->mp4_240;
instead of print $obj->{'response'}->{'items'}->{'files'}->{'mp4_240'};

Cake PHP Link Doesn't Display

I have string like "Venditoris: Beware of Scams » Blog Archive » Trilegiant Complaints ..." in Database but when I try to display it ,It is not displaying.
So,I used html_entity_decode function but still it is not display.
I am Using cakePHP.below is my code to display that links.
echo $html->link(html_entity_decode(
$listing_end_arr[$i]['Listing']['listing_title'],ENT_QUOTES),
$listing_end_arr[$i]['Listing']['listing_url'],
array('target'=>'_blank', 'style'=>'color:'
. $colorArr[$listing_end_arr[$i]['Listing']['listing_sentiment']])) ;
Please Help me.
Check the CakePHP manual if you are using $html->link correctly. If so, var_dump the return value instead of echoing it. If it is empty, do
var_dump( $listing_end_arr[$i]['Listing'] );
to see what the Listing key contains. If the desired content is not in the dump, you know the error is elsewhere; probably in fetching the string from where it is stored.
Also, instead of using array[n][foo][bar][baz], consider assigning the subarray to a variable while looping over the array, e.g. $listing = array[n][foo][bar], so you can just do $listing[baz]. This will dramatically increase readability of your code.
inspect generated html first.. your code should echo a link, maybe it's just not visible (styling, color..).

Categories