"Hey guys, struggling with a curl_init get request in PHP. Anyone got a simple example?"
So I'm trying to fetch some data from an API using curl_init get request, but it's not returning what I expect.
Maybe I'm missing something basic? Like, do I need to set CURLOPT_RETURNTRANSFER or something?
Here's what I’ve got:
```php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://example.com/api");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
```
Is this correct? Or am I totally off?
Also, any best practices for handling errors? Sometimes it just fails silently and I’m like... *why?*
Thanks in advance! 🙏
So I'm trying to fetch some data from an API using curl_init get request, but it's not returning what I expect.
Maybe I'm missing something basic? Like, do I need to set CURLOPT_RETURNTRANSFER or something?
Here's what I’ve got:
```php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://example.com/api");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
```
Is this correct? Or am I totally off?
Also, any best practices for handling errors? Sometimes it just fails silently and I’m like... *why?*
Thanks in advance! 🙏
