WordPress.org

Ready to get started?Download WordPress

Forums

Get URI Contents (3 posts)

  1. ryanve
    Member
    Posted 1 year ago #

    Does WP have a built-in function that can read the contents of a URI into a string? I'm using the function below but I'm curious if WP already has something for that I can use.

    function get_uri_contents($uri)
    {
    	if ( empty($uri) || !is_string($uri)) { return false; }
    	$ch = curl_init($uri);
    	curl_setopt($ch, CURLOPT_REFERER, $uri);
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    	$str = curl_exec($ch);
    	curl_close($ch);
    	return $str;
    }
  2. Jeremy Clark
    Moderator
    Posted 1 year ago #

    You can use wp_remote_get. It returns and array of info about the uri. The key of body will return the body of the site.

    http://codex.wordpress.org/Function_API/wp_remote_get

  3. ryanve
    Member
    Posted 1 year ago #

    @Jeremy Awesome thanks, that looks like it should do the trick =]

Topic Closed

This topic has been closed to new replies.

About this Topic