How to get Alternative to file get contents

0 votes

This is my code:

$xml_file = file_get_contents(SITE_PATH . 'cms/data.php');

The problem is that a server has URL file-access disabled. I cannot enable it, its a hosting thing.

So the question is this. The data.php file generates xml code.

How can I execute this and get the xml data without doing the above method?

Is it possible?

Nov 8, 2020 in PHP by kartik
• 37,520 points
6,149 views

1 answer to this question.

0 votes

Hii,

Use cURL. This function is an alternative to file_get_contents.

function url_get_contents ($Url) {
    if (!function_exists('curl_init')){ 
        die('CURL is not installed!');
    }
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $Url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;
}

Hope it helps!!

answered Nov 9, 2020 by Niroj
• 82,840 points

Related Questions In PHP

0 votes
1 answer

How to get xdebug var_dump to show full object/array?

Hello. These are configurable variables in php.ini: ; with ...READ MORE

answered Apr 7, 2020 in PHP by Niroj
• 82,840 points
3,689 views
0 votes
1 answer

How to get the client IP address in PHP ?

Hello, Here is a code sample of a good ...READ MORE

answered Apr 8, 2020 in PHP by Niroj
• 82,840 points
6,969 views
0 votes
1 answer

How to get current route in Symfony 2?

Hii,  The easiest way to do this: class MyController ...READ MORE

answered Apr 15, 2020 in PHP by Niroj
• 82,840 points
1,631 views
0 votes
1 answer

How to get the current plugin directory in WordPress?

Hello @kartik, This will actually get the result ...READ MORE

answered May 8, 2020 in PHP by Niroj
• 82,840 points
4,459 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
23,012 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
2,995 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
2,918 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
44,696 views
0 votes
1 answer

How to get file_get_contents() to work with HTTPS?

Hello @kartik, Try the following script to see ...READ MORE

answered Sep 1, 2020 in PHP by Niroj
• 82,840 points
4,651 views
0 votes
1 answer

How to get thumbnail of youtube video from youtube API?

Hii @kartik, If you want the biggest image ...READ MORE

answered Apr 1, 2020 in PHP by Niroj
• 82,840 points
1,649 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP