Modify your PHP web service, factors.php to return the prime factors of a
provided number in JSON format. For example, the request factors.php?n=264
would return:
{"number": 264, "factors": [2, 2, 2, 3, 11]}
You can try out the service here.
header('Content-type: application/json'); if (!isset($_GET['n'])) { header('HTTP/1.1 400 Invalid Request'); print "Please provide a parameter n."; } else { $n = $_GET["n"]; $ret = array( "number" => $n, "factors" => factorize($n), ); print json_encode($ret); }