-1

well, if you're confused so am i, so to make it better for you to understand what i'd like to do this is what i think

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://google.com/a-good-coffee');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
//sleep(6);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'blablabla123abc');
echo $func = curl_exec($ch);

let's say $func will return this { "id": "great_coffee", "object": "amazing", "billing_details": google } what i do want to achieve is this i want $func only to read the text in the second " " which is "great_coffee", the result will randomize each time i curl the same page (lets say it's gonna be a_good_life next time i curl) so i dont want to get a specific value, ? *Is this possible ? and how could i do it if it is ?

Thank you for your responses, but if i use json_decode i will get the id yes, but i will still get some blank lines

  • Why wouldn't you just decode the json and extract the `id` value? I don't get why the circuitous route to an otherwise very direct thing. – Sherif Feb 07 '20 at 21:33
  • but if i use json_decode i will get the id yes, but i will still get some blank lines – Andrew Jetun Feb 07 '20 at 21:38
  • I don't know what you mean by "blank lines" here. You will get a native PHP object from decoding the json. – Sherif Feb 07 '20 at 21:47
  • just a lot of spacing ( around 2 lines ) – Andrew Jetun Feb 07 '20 at 21:51
  • I have no idea what you mean by "a lot of spacing". It does exactly what you want. Beyond that I'm at a loss for how else to help you. – Sherif Feb 07 '20 at 21:52
  • and i'm very thankful for helping me on that part. also this is the result i get, maybe you have some ideas? `moonandstars ‎‎‎‎‎‎‎‎‎‎‎ ` – Andrew Jetun Feb 07 '20 at 21:54
  • Could you maybe be looking for the [trim](https://www.php.net/manual/en/function.trim.php) PHP function? – Matthew Anderson Feb 07 '20 at 21:54
  • i tried trimming then str replace – Andrew Jetun Feb 07 '20 at 21:55
  • Can you post an example of the string you're referring to with extra blank lines? – Matthew Anderson Feb 07 '20 at 21:59
  • this string `moonandstars ‎‎‎‎‎‎‎‎‎‎‎ `and imagine the little blank that i added being a lot of spacing(2 lines aprox.)` – Andrew Jetun Feb 07 '20 at 22:03
  • **[You should not switch off `CURLOPT_SSL_VERIFYHOST` or `CURLOPT_SSL_VERIFYPEER`](https://paragonie.com/blog/2017/10/certainty-automated-cacert-pem-management-for-php-software)**. It could be a security risk! [Here is how to get the certificate bundle if your server is missing one](https://stackoverflow.com/a/32095378/1839439) – Dharman Feb 08 '20 at 17:45

1 Answers1

-1

Yes, the first thing you'd want to do is decode the result into an array using json_decode Then you can get the array values only by using the array_values function. From there you just need to get the second index.