Skip to content

Instantly share code, notes, and snippets.

<?php
# error_hash to hold error numbers and messages
# must be kept in the config file
$error_hash = array(
1000 => 'Currency type not recognized',
1100 => 'Required parameter is missing',
1200 => 'Parameter not recognized',
1300 => 'Currency amount must be a decimal number',
1400 => 'Error in service',
<?php
# always include this line (in config file in final version)
@date_default_timezone_set("GMT");
# the function to generate errors (in functions file in final version)
require_once('generate_error.php');
# exit if core data files are missing
if (!file_exists('rates.xml') || !file_exists('currencies.xml')) {
echo generate_error(1400, $error_hash, 'xml');
<?php
# TESTS for catch_errors.php
# Not enough params (format missing)
# header('Location: catch_errors.php?from=USD&to=GBP&amnt=10.00');
# Too many params (other added)
# header('Location: catch_errors.php?from=USD&to=GBP&amnt=10.00&format=xml&other=value');
# from param is not recognized
[
{
"id": 2,
"name": "An ice sculpture",
"price": 12.50,
"tags": ["cold", "ice"],
"dimensions": {
"length": 7.0,
"width": 12.0,
"height": 9.5
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Product set",
"type": "array",
"items": {
"title": "Product",
"type": "object",
"properties": {
"id": {
"description": "The unique identifier for a product",
<?xml version="1.0" encoding="UTF-8"?>
<customers>
<customer>id="75035578"> <name>
<first>Joseph</first>
<middle>Michael</middle>
<last>Bloggs</last>
<preferred>Joe</preferred>
<title>Mr</title>
</name>
<address>
<?xml version="1.0" encoding="UTF-8"?>
<customers>
<customer>id="75035578"> <name>
<first>Joseph</first>
<middle>Michael</middle>
<last>Bloggs</last>
<preferred>Joe</preferred>
<title>Mr</title>
</name>
<address>
<!DOCTYPE html>
<html>
<head>
<title>AJAX pull XML Example</title>
<style>
textarea {
outline: none;
resize: none;
width: 400px;
<!DOCTYPE html>
<html>
<head>
<title>AJAX pull XML Example</title>
<style>
textarea {
outline: none;
resize: none;
width: 400px;
<!DOCTYPE html>
<html>
<head>
<title>AJAX pull XML Example</title>
<style>
textarea {
outline: none;
resize: none;
width: 400px;