I'm developing a site for analyzing a store's data.
I need the url part of my array to look like this:
array(
'url' => 'http://some.website.com:8080/SASStoredProcess/do?_username=user-123',
'_password' => 'passwd',
'_program' => '/Utilisateurs/DARTIES3-2012/Mon dossier/analyse_dc',
'annee' => '2012',
'ind' => 'V',
'_action' => 'execute'
);
I currently have this and am struggling to convert it to the desired format:
array(
'url' => 'url=http://some.website.com:8080/SASStoredProcess/do?_username=user-123&_password=passwd&_program=%2FUtilisateurs%2FDARTIES3-2012%2FMon+dossier%2Fanalyse_dc&annee=2012&ind=V&_action=execute',
'otherKey' => 'otherValue'
);
Please can somebody help me to convert the URL in the second code block to look like the first code block? Thanks in advance.
So this will extract the url in the form you want, as $url:
$myArray = array(
'url' => 'url=http://some.website.com:8080/SASStoredProcess/do?_username=user-123&_password=passwd&_program=%2FUtilisateurs%2FDARTIES3-2012%2FMon+dossier%2Fanalyse_dc&annee=2012&ind=V&_action=execute',
'otherKey' => 'otherValue'
);
parse_str($myArray['url']);
echo $url;
You will need to decide where it needs to go next and how you get it there.
You might want to use: parse_url() and parse_str() over your $array['url']
Related
OK I am stumped.
I have tried numerous different approaches and I've spent the best part of a good few hours searching to no avail to my exact situation, that or I am tired and blind.
Here is the raw json pulled from a URI using file_get_contents():
{"id":"XXX","name":"Customer1","os":"CentOS Linux 7.3.1611 Core","cpu_type":"Intel(R) Xeon(R) CPU E3-1245 V2 # 3.40GHz","networking_v4":[{"addr":"xxx.xxx.xxx.xxx","if":"eth0"}],"networking_v6":[{"addr":"xxxx","if":"eth0"},{"addr":"xxxx","if":"eth0"}],"agent_version":0.96,"status":"up","last_update":1505949230,"first_update":1500588943,"notifications_count":8,"ip_whois":{"ip":"xxx.xxx.xxx.xxx","hostname":"xxx","city":"Garwood","region":"New Jersey","country":"US","loc":"xxx","org":"AS20473 Choopa, LLC","postal":"xxx"},"additional_fields":[{"value":"xxx","key":"Datacenter"},{"value":"","key":""},{"value":"","key":""},{"value":"","key":""},{"value":"","key":""},{"value":"","key":""},{"value":"","key":""},{"value":"","key":""},{"value":"","key":""}]}
As you can see its a pretty simple request and I have every bit of data except those nested within networking_v4 and networking_v6.
I tried to access those like so:
'ipv4' => $json->networking_v4->addr,
'ipv4dev' => $json->networking_v4->if,
'ipv6' => $json->networking_v6->addr,
'ipv6dev' => $json->networking_v6->if,
Here is the full snapshot of code in its entirety:
$content = file_get_contents($url);
$json = json_decode($content);
$server_lastupd = $json->last_update;
$server_firstupd = $json->first_update;
$server = array(
'id' => $json->id,
'name' => $json->name,
'os' => $json->os,
'cputype' => $json->cpu_type,
'ipv4' => $json->networking_v4->addr,
'ipv4dev' => $json->networking_v4->if,
'ipv6' => $json->networking_v6->addr,
'ipv6dev' => $json->networking_v6->if,
'status' => $json->status,
'lastupd' => $json->$server_lastupd,
'firstupd' => $json->$server_firstupd,
'notifications' => $json->notifications_count,
'ip' => $json->ip_whois->ip,
'hostname' => $json->ip_whois->hostname,
'city' => $json->ip_whois->city,
'region' => $json->ip_whois->region,
'country' => $json->ip_whois->country,
'loc' => $json->ip_whois->loc,
'org' => $json->ip_whois->org,
'postal' => $json->ip_whois->postal,
'dctag' => $json->additonal_fields->dctag,
'source' => "XXX"
);
return $server;
So my issue is I appear to be unable to access the child content within networking_v4 and networking_v6.
Any help on this would be massively appreciated, its stumped me for the best part of 6 hours last night and a few more today, so I give in, someone please show me the light!
Many thanks :)
It looks like those are nested in arrays from the [{"key':"value"},{"key":"value"}] square brackets. have you tried
ipv4 => $json->networking_v4[0]->addr,
Try $json->networking_v4[0]->addr.
Both the networking_v4 and the networking_v6 keys point to arrays, so you need to pick which index you want to look at. The former only has one element, so it's easy to pick index 0, but the latter has multiple elements, so you'll need to figure out which one you want.
First of all this is my code:
Log::create([
'action' => $event->changes[0], //<- This is my problem
'object_id' => $event->id,
'object_type' => "Account",
'ip_address' => Request::ip(),
'user' => ucfirst(Auth::user()->name),
'time' => Carbon::now()->format('H:i:s'),
'date' => Carbon::now()->format('Y-m-d')
]);
$event->changes is an array which contains many items but i only know how to get 1 specific item at a time using the index [0] or [1] etc.
How do I get all the values to display instead of 1 at a time? Obviously I don't want to create a new log for each single action but I cant figure out how to do this.
As always any help is appreciated thank you.
You need to serialize the $event->changes if you want it within one log entry.
It actually depends on the structure of changes array, but it seems to be an array of strings, so you may for example use the implode(', ', $changes), so the snippet would look the following:
Log::create([
'action' => implode(', ', $event->changes), //<- This is my problem
'object_id' => $event->id,
'object_type' => "Account",
'ip_address' => Request::ip(),
'user' => ucfirst(Auth::user()->name),
'time' => Carbon::now()->format('H:i:s'),
'date' => Carbon::now()->format('Y-m-d')
]);
I'm having trouble finding how to get the Urls from named routes inside a Phalcon PhP controller. This is my route:
$router->add(
'/admin/application/{formUrl:[A-Za-z0-9\-]+}/{id:[A-Za-z0-9\-]+}/detail',
[
'controller' => 'AdminApplication',
'action' => 'detail'
]
)->setName("application-details");
I want to get just the Url, example: domain.com/admin/application/form-test/10/detail . With the code below I can get the html to create a link, the same result of the link_to.
$url = $this->tag->linkTo(
array(
array(
'for' => 'application-details',
'formUrl' => $form->url,
'id' => $id
),
'Show'
)
);
The result I want is just the Url. I'm inside a controller action. I know it must be really simple, I just can't find an example. Can you help me?
Thanks for any help!
You should use the URL helper. Example:
$url = $this->url->get(
[
'for' => 'application-details',
'formUrl' => $form->url,
'id' => $id,
],
[
'q' => 'test1',
'qq' => 'test2',
]
);
You can pass second array for query string params if needed.
According to your route definition, the above should output something like:
/admin/application/form-url/25/detail?q=test1&qq=test2
More info of Generating URIs in the docs.
Need some help. Have this code in PaymentModule.php in Prestashop:
$params = array(
'{voucher_amount}' => Tools::displayPrice($voucher->reduction_amount, $this->context->currency, false),
'{voucher_num}' => $voucher->code,
'{firstname}' => $this->context->customer->firstname,
'{lastname}' => $this->context->customer->lastname,
'{id_order}' => $order->reference,
'{order_name}' => $order->getUniqReference()
);
I use $params['firstname'] for showing customer firstname and get nothing. I insert $params['firstname'] in /modules/bankwire/bankwire.php
Please tell me where I make a mistake?
Thanks
In your array you have a {firstname} key, but no firstname key.
If you want to get value, you should use: $params['{firstname}']
Try
$params = array(
'voucher_amount' => Tools::displayPrice($voucher->reduction_amount, $this->context->currency, false),
'voucher_num' => $voucher->code,
'firstname' => $this->context->customer->firstname,
'lastname' => $this->context->customer->lastname,
'id_order' => $order->reference,
'order_name' => $order->getUniqReference()
);
or in the case that volkerk is right, try
$params['{firstname}']
there is variables for email template, it's just assoc array, for access use
$params['{voucher_amount}']
I'm using drupal's l() function to build a link. So I'm passing this variable as a second argument that the function will generate the href value from.
$performer = $row->node_field_data_field_evenement_performer_title;
$url = 'node/' . $row->node_field_data_field_evenement_performer_nid . '/lightbox2';
print l($performer, $url, array('html' => TRUE, 'attributes' => array('rel' => 'lightframe[group|width:500px; height: 500px][caption]', 'class' => 'performer-link')));
The URL should end with the query string ?format=simple. So basically my $url variable should be updated something like:
$url = 'node/' . $row->node_field_data_field_evenement_performer_nid . '/lightbox2?format=simple';
No matter what encode/decode function I wrap around, and whatever escaping I do, that question mark and equals sign keep getting interpreted as %25 types of characters.
I tried:
$url = 'node/' . $row->node_field_data_field_evenement_performer_nid . '/lightbox2\?format\=simple');
or
'/lightbox2' . any_decode_or_encode_function_outthere('?format=simple');
but I keep getting URLs like node/202/lightbox2%5C%3Fformat%5C%3Dsimple.
Use the query key for the options array passed to l():
print l($performer, $url, array(
'html' => TRUE,
'attributes' => array(
'rel' => 'lightframe[group|width:500px; height: 500px][caption]',
'class' => 'performer-link'
),
'query' => array(
'format' => 'simple'
)
));
l() calls url() internally, and options can be forwarded on. See the docs for url()
Try l($performer, $url, array('query' => array('format' => 'simple'), /*...the rest of your array...*/ );
This is for drupal 7. In the options array you can specify a query array which is a key-value array of things to append to the url query string.