PHP 5.3.10: var_dump does not print readable results as it used to be - php-5.3

After I have upgraded my localhost wamp server to php 5.3.10, the var_dump does not print results that are as readable/pretty as they used to be.
$obj = (object) array('qualitypoint', 'technologies', 'India');
var_dump($obj);
object(stdClass)#2 (3) { [0]=> string(12) "qualitypoint" [1]=> string(12) "technologies" [2]=> string(5) "India" }
As you can see that everything now is cramp into one line.
It used to print something like this below though,
object(stdClass)#1 (3) {
[0]=> string(12) "qualitypoint"
[1]=> string(12) "technologies"
[2]=> string(5) "India"
}
How can I make var_dump to return a readable formatted result?

object(stdClass)#2 (3) { [0]=> string(12) "qualitypoint" [1]=> string(12) "technologies" [2]=> string(5) "India" }
Is normal PHP output for this code:
$obj = (object) array('qualitypoint', 'technologies', 'India');
var_dump($obj);
For more readable format You probably used Xdebug extension for PHP.
Check You PHP extensions directory (PHP directory/ext/ on Windows).
If there is not file with name like this:
php_xdebug-X.X.X-X.X-vcX.dll
Download one for You PHP version
Put it in extensions directory add to PHP configuration (php.ini file) bellow other PHP extensions.
Example:
zend_extension=PHP_EXTENSIONS_ABSOLUTE_PATH\php_xdebug-2.1.2-5.3-vc9.dll
Restart Apache and var_dump() output will be formatted like this:
object(stdClass)[1]
string 'qualitypoint' (length=12)
string 'technologies' (length=12)
string 'India' (length=5)

Try:
echo '<pre>';
var_dump($obj);
echo '</pre>';

Related

Transform request data in Krakrnd with lua

Using Krakend as api gateway.
I have an endpoint configured in krakend.json:
"endpoint":"/call",
"extra_config":{
"github.com/devopsfaith/krakend-lua/proxy":{
"sources":[
"/function.lua"
],
"pre":"pre_backend(request.load())",
"live":true,
"allow_open_libs":true
}
},
"method":"POST",
"output_encoding":"json",
"headers_to_pass":[
"*"
],
"backend":[
{
"url_pattern":"/api/v1/get_client_id",
[...]]
},
The endopont "/api/v1/get_client_id" recives just a param:
{"user_mail_1":"test#test.es"}
I want, whith the lua script my endopoint "/call" recives:
{"email":"test#test.es"}
and transform on before send:
{"user_mail_1":"test#test.es"}
I tried with gsub, but use body() as "string" is no efficient.
function pre_backend( req )
print('--Backend response, pre-logic:');
local r = req;
r:params('test','test');
r:query('lovelyquery')
r:body('test','test');
lolcal v = r:body():gsub('email', 'user_mail_1')
...
Is a way to parse "req" as a table, dict or something i can transform data?
Is another way to transform REQUEST data?
EXAMPLE WORKING WITH GSUB:
function pre_backend( req )
print('--Backend response, pre-logic:');
print('--req');
print(req);
print(type(req));
local r = req;
print('--body');
print(type(r:body()));
print(r:body())
local body_transformed = r:body():gsub('email', 'user_mail_1');
print('--body_transformed');
print(body_transformed);
print(type(body_transformed));
end
Console output:
2022/02/11 09:59:52 DEBUG: [http-server-handler: no extra config]
--Backend response, pre-logic:
--req
userdata: 0xc0004f9b60
userdata
--body
string
{"email" : "test#test.es","test_field":"email"}
--body_transformed
{"user_mail_1" : "test#test.es","test_field":"user_mail_1"}
string
As we can see the gsub is not efficient becouse replace all strings.
If I can work with req as table, dict or something similar, I can replace dict key/value. ex: req['xxx] = 'xxx' or iterate req.keys
gsub stands for global substitution. It replaces all occurances of the pattern in the string.
If you just want to replace "email" infront of an email address simply use a pattern that takes this into account.
print((r:body():gsub('(")(email)("%s-:%s-"%w+#%w+%.%w+")', "%1user_mail_1%3")))
Alternatively if you knwo that you only want to replace the first occurance of email you can simply do this:
print((r:body():gsub("email", "user_mail_1", 1)))
The thrid parameter will stop gsub after the first replacement.

parsing JSON file using telegraf input plugin : unexpected Output

I’m new to telegraf and influxdb, and currently looking forward to exploring telegraf, but unfortunetly, I have some difficulty getting started, I will try to explain my problem below:
Objectif: parsing JSON file using telegraf input plugin.
Input : https://wetransfer.com/downloads/0abf7c609d000a7c9300dc20ee0f565120200624164841/ab22bf ( JSON file used )
The input json file is a repetition of the same structure that starts from params and ends at it.
you find below the main part of the input file :
{
"events":[
{
"params":[
{
"name":"element_type",
"value":"Home_Menu"
},
{
"name":"element_id",
"value":""
},
{
"name":"uuid",
"value":"981CD435-E6BC-01E6-4FDC-B57B5CFA9824"
},
{
"name":"section_label",
"value":"HOME"
},
{
"name":"element_label",
"value":""
}
],
"libVersion":"4.2.5",
"context":{
"locale":"ro-RO",
"country":"RO",
"application_name":"spresso",
"application_version":"2.1.8",
"model":"iPhone11,8",
"os_version":"13.5",
"platform":"iOS",
"application_lang_market":"ro_RO",
"platform_width":"320",
"device_type":"mobile",
"platform_height":"480"
},
"date":"2020-05-31T09:38:55.087+03:00",
"ssid":"spresso",
"type":"MOBILEPAGELOAD",
"user":{
"anonymousid":"6BC6DC89-EEDA-4EB6-B6AD-A213A65941AF",
"userid":"2398839"
},
"reception_date":"2020-06-01T03:02:49.613Z",
"event_version":"v1"
}
Issue : Following the documentation, I tried to define a simple telegraf.conf file as below:
[[outputs.influxdb_v2]]
…
[[inputs.file]]
files = ["/home/mouhcine/json/file.json"]
json_name_key = "My_json"
#... Listing all the string fields in the json.(I put only these for simplicity reason).
json_string_fields = ["ssid","type","userid","name","value","country","model"]
data_format = "json"
json_query= "events"
Basically declaring string fields in the telegraf.conf file would do it, but I couldn’t get all the fields that are subset in the json file, like for example what’s inside ( params or context ).
So finally, I get to parse fields with the same level of hierarchy as ssid, type, libVersion, but not the ones inside ( params, context, user).
Output : Screen2 ( attachment ).
OUTPUT
By curiosity, I tried to test the documentation’s example, in order to verify whether I get the same expected result, and the answer is no :/, I don’t get to parse the string field in the subset of the file.
The doc’s example below:
Input :
{
"a": 5,
"b": {
"c": 6,
"my_field": "description"
},
"my_tag_1": "foo",
"name": "my_json"
}
telegraf.conf
[[outputs.influxdb_v2]]
…
[[inputs.file]]
files = ["/home/mouhcine/json/influx.json"]
json_name_key = "name"
tag_keys = ["my_tag_1"]
json_string_fields = ["my_field"]
data_format = "json"
Expected Output : my_json,my_tag_1=foo a=5,b_c=6,my_field="description"
The Result I get : "my_field" is missing.
Output: Screen 1 ( attachement ).
OUTPUT
By the way, I use the influxdb cloud 2, and I apologize for the long description of this little problem, I would appreciate some help please :), Thank you so much in advance.

Get users yahoo email

I think this yahoo email of users is little problem with yahoo and twitter.
I have searched many days for this but no luck.
Im getting user details like that
print( $profile->location) ; --------got location
print( $profile->gender) ; --------- got gender
But when i want to get the email i couldnt .
Have tried this
print( $profile->emails->handle) ;
But i got this error
Notice: Trying to get property of non-object in mywebsite/index.php on line 103
Have tried this
print( $profile->emails['handle']) ; -----no luck
I have seen this but it seems there are many emails .
How can i get the main email ?
Thanks
EDIT:
i have tryed this
foreach($profile->emails as $k){
echo 'handle: ' . $k->handle . ' -----> i got error here 'Undefined property: stdClass::$handle'
id: ' . $k->id . ' -----> i got the id (no error)
type: ' . $k->type . '<br>'; -----> i got the type (no error)
}
i dont know why handle returns error always . is something wrong with handle ?
EDIT2:
i have made this:
var_dump($profile);
and it gives this
object(stdClass)#14 (20)
{ ["uri"]=> string(70)
"http://social.yahooapis.com/v1/user/1JKK3SDVWE6QDPAQRVUFRN7NDU/profile"
["guid"]=> string(26) "1J4K3SDVSW6QDPQQRVU1RN7NDO"
["birthYear"]=> int(1977)
["birthdate"]=> string(3) "12/8"
["created"]=> string(20) "2006-10-08T10:32:21Z"
["displayAge"]=> int(37)
["emails"]=> array(1) { [0]=> object(stdClass)#22 (3) { ["id"]=> int(3)
["primary"]=> bool(true)
["type"]=> string(4) "HOME"} }
["familyName"]=> string(0) ""
["gender"]=> string(1) "M"
["givenName"]=> string(0) ""
["image"]=> object(stdClass)#23 (4) { ["height"]=> int(192)
["imageUrl"]=> string(55) "http://l.yimg.com/dh/ap/social/profile/profile_U197.png"
["size"]=> string(7) "192x192"
["width"]=> int(192) }
["lang"]=> string(5) "en-UK"
["location"]=> string(31) "NA, Indisponible ENGLAND 16548"
["memberSince"]=> string(20) "2003-05-10T21:34:41Z"
["nickname"]=> string(5) "diFirst"
["profileUrl"]=> string(51) "http://profile.yahoo.com/1J4K3SDVSE6ADPQQRVJFRN7ND1" ["searchable"]=> bool(true)
["timeZone"]=> string(12) "Europe/ENGLAND"
["updated"]=> string(20) "2012-09-21T14:35:30Z"
["isConnected"]=> bool(false)
}

text file -> json -> ios array

I have a file with the following format:
/Users/devplayerx/Sandbox/pics/images/001012DG-161.JPG
pixelWidth: 1600
pixelHeight: 1050
filename: 001012DG-161.JPG
/Users/devplayerx/Sandbox/pics/images/001019DG-151 COPY.JPG
pixelWidth: 1600
pixelHeight: 1050
filename: 001019DG-151 COPY.JPG
and would like to, ultimately, have an iOS dictionary with the filename as key, and either a dictionary or array with the pixelWidth and pixelHeight as value. I was considering converting my text file into a JSON file, and then parse it using NSJSONSerialization, but I'm not sure how to convert my text file into JSON. Also, I'd like to remove the full path from the text file, since it's not needed.
Here is a perl script that seems to do the job:
#!/usr/bin/perl
use strict;
use warnings;
open FILE,"< yourfile.txt" or die "I/O error : $!\n";
my $w = 0;
my $h = 0;
my $f = "";
print "{\n";
while (my $line = <FILE>)
{
if ($f)
{
print ",\n";
$f = "";
}
if ($line =~ /pixelWidth: ([0-9]+)/)
{
$w = $1;
}
if ($line =~ /pixelHeight: ([0-9]+)/)
{
$h = $1;
}
if ($line =~ /filename: (.*)$/)
{
$f = $1;
print "\t\"$f\" : [ $w, $h ]"
}
}
print "\n}\n";
close FILE;
Note that I'm not an expert in perl so maybe it can be improved, but using it on your input file seems to produce your expected JSON as below:
prompt$ perl scr.pl
{
"001012DG-161.JPG" : [ 1600, 1050 ],
"001019DG-151 COPY.JPG" : [ 1600, 1050 ]
}
Note that once you have your JSON file, you may optionally convert it into a PLIST file using the plutil tool. For example perl scr.pl | plutil -convert binary1 -o yourfile.plist - will create yourfile.plist from the JSON produced by perl scr.pl (my script above). You can then easily read this file in your code using [NSDictionary dictionaryWithContentsOfFile:pathToYourFilePlist] and directly have access to your data as an NSDictionary in one line.
The json object could look like this:
{ picture: { path : "thePath", pixelWidth: 1600, pixelHeight: 1050, filename : "name" }}
I would then convert it by taking the rows and putting them in a list, looping through the list and eventually spitting everything out in another text file using the above object notation.
What language do you need to write the tooling to convert it to json in?
You can use NSInputStream to read the text file, on each iteration you can build your dictionary the way you want.
After that just use NSJSONSerialization.

How to detect if the path of a url starts with a certain word

I'm trying to figure out how to get the page name from a facebook page and although I've figured out how to get it from the http://www.facebook.com/pagename version, I can't figure out how to test and get it from the longer version that looks like this http://www.facebook.com/pages/pagename/433425324544. How can I test to see if the path starts with /pages and how can I extract the pagename from it all using one function. Here's what I use to get the page name in the standard form.
function get_facebook_username( $facebook_url ) {
$url = $facebook_url;
$result = preg_match("/(https|http)?:\/\/(www\.)?facebook\.com\/?([^\/]*)/", $url, $matches);
$fb_username = 'default value';
if($result == 1){
$fb_username = $matches[3];
} else {
return;
}
echo "$fb_username";
}
I found a better way to do this I think except it cuts the last letter off the username if the url is in it's shortened version. For example.
//---short
$url = http://www.facebook.com/pagename
//---long
$url = http://www.facebook.com/pages/pagename/7532527927346
<?php
$url = $facebook_username;
$path = parse_url($url, PHP_URL_PATH);
$pathTrimmed = trim($path, 'pages/../0123456789');
echo $pathTrimmed;
?>
//---short
pagenam
//---long
pagename
Why is the short version missing the last letter?
The way I would go about this is to use explode to place the url into an array using the below code:
$url = "http://www.facebook.com/pages/pagename/7532527927346";
$result = explode("/", $url);
You get the following array:
array(6) {
[0]=>
string(5) "http:"
[1]=>
string(0) ""
[2]=>
string(16) "www.facebook.com"
[3]=>
string(5) "pages"
[4]=>
string(8) "pagename"
[5]=>
string(13) "7532527927346"
}
Then a simple if $result[3] == "pages" will allow you to check if the url contains pages.
Ninja Edit
In place of explode, you can also use the preg_split which will return no empty array elements:
$result = preg_split("~/~", $url, -1, PREG_SPLIT_NO_EMPTY);

Resources