How to concatenate two strings and save the result in a variable?

Asked

Viewed 199 times

0

I’m wearing a API to capture proxies. She returns to me the proxies in format JSON, as follows:

{
    "_links": {
        "_self": "\ / proxy",
        "_parent": "\ /"
    },
    "ip": "45.55.23.78",
    "porto": 1080,
    "protocolo": "socks5",
    "anonimato": "alto anonimato",
    "LastTested": "2018-03-09 06:51:27",
    "permiteRefererHeader": true
    "permiteUserAgentHeader": true
    "permiteCustomHeaders": true,
    "permiteCookies": true
    "permitePost": verdadeiro,
    "permiteHttps": true
    "país": "EUA",
    "connectTime": "0.721",
    "downloadSpeed": "160,000",
    "secondsToFirstByte": "1.079",
    "tempo de atividade": "99.164"
}

I want to get just the IP and the door, but I need to put the two together to stay this way the result: 45.55.23.78:1080.

I was capturing it that way:

$f = file_get_contents("link da minha api");
$json = json_decode($f);
 $proxy = $json->ip;
 $porta = $json->port;  

Only I need you both to stay in one variable, for example $ipPort = $json->ip:port. It’s just an example, I don’t know how to do this so I need your help.

  • 1

    It is also possible to do as follows: $proxy = "{$json->ip}:{$json->port}"; or sprintf("%s:%s", $json->ip, $json->port);

1 answer

0


As per your example:

 $proxy = $json->ip;
 $porta = $json->port;  

 $full = $json->ip.":".$json->port;
 echo $full;

outworking:

127.0.0.1:80

Browser other questions tagged

You are not signed in. Login or sign up in order to post.