Converting the code that fopen uses for curling, as the host blocks fopen

I am working on Wordpress and I know nothing about PHP . I am trying to get a post-excerpt scroller to work, but it uses fopen() , but it is disabled on my clients host.

 $f = fopen( $url, 'r' ); while( $data = fread( $f, 4096 ) ) { $xml .= $data; } fclose( $f ); 

Can this just be written in curl?

Thanks in advance!

+4
source share
2 answers

it should work

 $xml = file_get_contents($url); 
+1
source
 $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_HEADER, 0); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($ch); curl_close ($ch); 
0
source

Source: https://habr.com/ru/post/1435361/


All Articles