PhpFiddle APIs version 3.0

APIs with JSON response support W3C recommends XMLHttpRequest specification: Cross-Origin Resource Sharing, which defines a mechanism to enable client-side cross-origin requests. All Ajax requests can use these APIs to access PhpFiddle's features directly

In the following text code_id is a link id or gist id which generated by PhpFiddle from saving the code. link id is made up of '-' and 6 or 8 characters in lowercase, for example, dfi-q1d, ze5q-kpb9, and gist id is string in 7 or 20 characters defined by GitHub Gist, for example: 3691666, 3682451, ec165a789941a37e51d8

When using API from browser address, all "&" and "#" in values of parameter should be replaced with URL encoded characters "%26" and "%23" respectively if existed, for example, "http://phpfiddle.org/api/hash?algorithm=md5&data=abcd#1234" has to be "http://phpfiddle.org/api/hash?algorithm=md5&data=abcd%231234"

 

NAME Runs Code
DESCRIPTION Executes posted code and returns wrapped execution results in JSON
URL STRUCTURE http://phpfiddle.org/api/run/code/json
VERSION 2
METHOD POST
PARAMETER One pair of 'code' and non-empty value in query data is required, and multiple other name-value pairs in query data are available

If 'phptag=yes' pair existed in query data PhpFiddle would add '<?php ' and ' ?>' to value of 'code' at beginning and ending respectively
 
RESPONSE JSON in format: {"result" : Execution result JSON}
ERROR JSON in format: {"error" : "Error describing message"}
NOTE PhpFiddle wraps execution results in JSON automatically, no JSON encoding reqired in executed code. If JSON encoded data was output by executed code, decoding response result on the page, for example, JSON.parse(data.result)

 

NAME Gets raw contents from URL
DESCRIPTION Gets raw contents with CSS selector from code URL and returns wrapped contents in JSON
URL STRUCTURE http://phpfiddle.org/api/raw/url/json
VERSION 2
METHOD GET and POST
PARAMETER Pair of 'url=valid_URL' in query data is required

If 'selector=CSS_selector' pair existed in query data PhpFiddle would extract text contents with CSS selector from the page then return result JSON, and if 'selector=CSS_selector' and 'innerhtml=yes' pairs existed at the same time in query data PhpFiddle would extract HTML contents instead of text contents from the page
 
RESPONSE JSON in format: {"code" : Code contetns JSON}
ERROR JSON in format: {"error" : "Error describing message"}

 

NAME Gets raw contents from code_id
DESCRIPTION Gets raw code contents from code_id and returns wrapped code contents in JSON
URL STRUCTURE http://phpfiddle.org/api/raw/code_id/json
VERSION 2
METHOD GET and POST
PARAMETER None
RESPONSE JSON in format: {"code" : Code contetns JSON}
ERROR JSON in format: {"error" : "Error describing message"}

 

NAME Searches code
DESCRIPTION Search code from PhpFiddle's code repository with search keywords in code description and returns matched data with JSON format, and allow 'and' operator for keywords
 
URL STRUCTURE http://phpfiddle.org/api/search
VERSION 2
METHOD GET and POST
PARAMETER Pair of 'keywords=non_empty_value' in query data is required
RESPONSE JSON in format: {"links" : matched data JSON}
Sample return value

	{"links" : 
	 [
	   {
		  "id" : "nhr-juv",
		  "type" : "public",
		  "description" : "PHP GD line graph"
	   },
	   {
		  "id" : "3682451",
		  "type" : "gist",
		  "description" : "3D pie chart with GD library, code on github:gist"
	   }
	 ]
	}
				
ERROR JSON in format: {"error" : "Error describing message"}
Example

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<script type="text/javascript" src="/js/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="/js/phpjs/section.min.js"></script>

<script type="text/javascript">
	$(function(){
	   $.ajax({
		  url: "http://phpfiddle.org/api/search",
		  type: "POST",
		  data: "KeyWords=phpfiddle",
		  cache: false,
		  dataType: "json",
		  success: function(data) {
				   if (data.links) {
					  document.write("success");
					  dump(data);
				   } 
				   if (data.error) {
					  document.write(data.error);
				   }
			}
	   });
	});
</script>
</head>
<body>

</body>
</html>
		

 

NAME Extracts multi-part text from a web page
DESCRIPTION Extracts multi-part text from a web page with CSS selectors
URL STRUCTURE http://phpfiddle.org/api/acm/json
VERSION 2
METHOD GET and POST
PARAMETER "url=valid_page_url{&postdata=para1=val1%26para2=val2%26...}
&selector[1]=CSS_selector_1&type[1]=html_or_text
{&selector[2]=CSS_selector_2&type[2]=html_or_text{&selector[3]=...}}"

Parts between "{" and "}" are optional, "postdata=para1=val1%26para2=val2%26..."
is for sending data to "valid_page_url" with HTTP POST method, and
all character "&" and "#" in values of "url", "postdata" and "selector[n]"
( n is a non zero positive integer ) would be replaced by "%26" and "%23"
respectively if existed
 
RESPONSE JSON in format: {"result" : extracted data JSON}
ERROR JSON in format: {"error" : "Error describing message"}

 

NAME Hash
DESCRIPTION Generate a hash value in lowercase hexadecimal digit, supported algorithms include "md2", "md4", "md5", "sha1", "sha224", "sha256", "sha384", "sha512", "ripemd128", "ripemd160", "ripemd256", "ripemd320", "whirlpool", "tiger128,3", "tiger160,3", "tiger192,3", "tiger128,4", "tiger160,4", "tiger192,4", "snefru", "snefru256", "gost", "adler32", "crc32", "crc32b", "salsa10", "salsa20", "haval128,3", "haval160,3", "haval192,3", "haval224,3", "haval256,3", "haval128,4", "haval160,4", "haval192,4", "haval224,4", "haval256,4", "haval128,5", "haval160,5", "haval192,5", "haval224,5" and "haval256,5"
 
URL STRUCTURE http://phpfiddle.org/api/hash
VERSION 2
METHOD GET and POST
PARAMETER Pairs of "algorithm=supported_algorithm" and "data=message_to_be_hashed" in query data are required
RESPONSE JSON in format: {"result" : "lowercase hexadecimal digit"}
ERROR JSON in format: {"error" : "Error describing message"}

 

MySQL 5.6.33