Skip to main content

curl_init

Kurzbeschreibung

Startet eine cURL-Session.

Funktionsbeschreibung

curl_init( string $_url  ) :

Beispiele

{%
	# API data
	$_apiFunction = "ratingstars";
	$_svStoreID = "5675";
	$_apiKey = "28ea3dc072c326691814641c3daf5b7e";

	# Builds API URL retrieved
	$_apiUrl = "https://api.shopvote.de/ratings/v1/"
			   . $_apiFunction . "/"
			   . $_svStoreID . "/"
			   . $_apiKey;

	# Initializes Curl session
	$_ch = curl_init();

	# Prepares Useragent options as strings
	$_opt = "SVApiV1; L25ext for ShopID ";
	$_opt .= $_svStoreID;

	# Sets options for Curl session
	curl_setopt( $_ch , "CURLOPT_USERAGENT" , $_opt );
	curl_setopt( $_ch , "CURLOPT_HEADER" , false );
	curl_setopt( $_ch , "CURLOPT_RETURNTRANSFER" , 1 );
	curl_setopt( $_ch , "CURLOPT_URL" , $_apiUrl);

	# Runs Curl session and stores result
	$_output = curl_exec($_ch);

	# Closes Curl session
	curl_close($_ch);

	# If return value can be converted to simpleXML element,
	# element is cached and different values written to variables.
	if (simplexml_load_string($_output) != null)
	{
		$_xml = simplexml_load_string($_output);
		$_storename = $_xml->name;
		$_storeprofile = $_xml->profile;
		$_storeurl = $_xml->storeurl;
		$_rating_stars = $_xml->rating_summary->rating_value[0];
		$_rating_value = $_xml->rating_summary->rating_value[1];
		$_rating_count = $_xml->rating_summary->ratings_count;
		$_positive_rating_count = $_xml->rating_summary->ratings_positive;
		$_neutral_rating_count = $_xml->rating_summary->ratings_neutral;
		$_negative_rating_count = $_xml->rating_summary->ratings_negative;
	}
%}

<div>
	ShopVote rating of $_storeurl: $_rating_value (that are $_ratingstarts / 5 Stars) out of $_rating_count ratings.
</div>
Zum Seitenanfang