Skip to content

Instantly share code, notes, and snippets.

pchatterjee

Block or report user

Report or block pchatterjee

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View quotes.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Quotes XML -&gt; HTML using XSLT example</title>
<style>
tr:nth-child(odd){
background-color:#eeeeee;
}
View xsl_example.php
<?php
$xml = new DOMDocument();
$xml->load('quotes.xml');
$xsl = new DOMDocument;
$xsl->load('quotes_to_html.xsl');
$proc = new XSLTProcessor();
$proc->importStyleSheet($xsl);
View quotes_to_html.xsl
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8" indent="yes"/>
<xsl:template match="/">
<xsl:text disable-output-escaping="yes">&lt;!DOCTYPE html>&#10;</xsl:text>
<html>
<head>
<title>Quotes XML -> HTML using XSLT example</title>
<style>
tr:nth-child(odd){
View quotes.xml
<?xml version="1.0"?>
<quotes>
<quote cat="romantic">
<text>There is no remedy but to love more.</text>
<author>
<name>Henry David Thoreau</name>
<dob>1817</dob>
<dod>1862</dod>
<wplink>http://en.wikipedia.org/wiki/Henry_David_Thoreau</wplink>
<wpimg>http://upload.wikimedia.org/wikipedia/commons/f/f0/Benjamin_D._Maxham_-_Henry_David_Thoreau_-_Restored.jpg</wpimg>
View quotes.txt
quote|source|dob-dod|wplink|wpimg|category
There is no remedy but to love more.|Henry David Thoreau|1817-1862|http://en.wikipedia.org/wiki/Henry_David_Thoreau|http://upload.wikimedia.org/wikipedia/commons/f/f0/Benjamin_D._Maxham_-_Henry_David_Thoreau_-_Restored.jpg|romantic
There is always some madness in love. But there is also always some reason in madness.|Friedrich Nietzsche|1844-1900|http://en.wikipedia.org/wiki/Friedrich_Nietzsche|http://upload.wikimedia.org/wikipedia/commons/1/1b/Nietzsche187a.jpg|romantic
Love does not consist in gazing at each other, but in looking outward together in the same direction.|Antoine de Saint-Exupery|1900-1944|http://en.wikipedia.org/wiki/Antoine_de_Saint-Exupery|http://upload.wikimedia.org/wikipedia/commons/7/7f/11exupery-inline1-500.jpg|romantic
Take away love and our earth is a tomb.|Robert Browning|1812-1889|http://en.wikipedia.org/wiki/Robert_Browning|http://upload.wikimedia.org/wikipedia/commons/5/58/Robert_Browning_by_Herbert_Rose_Barraud_c1888.jpg|humerous
Work is
View quotes_csv2xml.php
<?php
# always include this line
@date_default_timezone_set("GMT");
$csv = file("quotes.csv");
$count = 1;
$xml = '<quotes>';
foreach($csv as $line) {
View php calculate function
// function to calculate and return result
function calc($x, $y, $op) {
if ($op == '/' && $y == 0) {
$prod = "&#8734";
}
else {
// build up the expression
$exp = "$x"."$op"."$y";
View calculator.php
<?php
/* ======================================================
PHP Calculator example using "sticky" form (Version 2)
======================================================
Author : P Chatterjee
Purpose : Simple example using a function.
View calculator.php
<?php
/* ======================================================
PHP Calculator example using "sticky" form (Version 1)
======================================================
Author : P Chatterjee (adopted from an original example written by C J Wallace)
Purpose : To multiply 2 numbers passed from a HTML form and display the result.
View calculator.php
<?php
/* ======================================================
PHP Calculator example using "sticky" form (Version 1)
======================================================
Author : P Chatterjee (adopted from an original example written by C J Wallace)
Purpose : To multiply 2 numbers passed from a HTML form and display the result.
You can’t perform that action at this time.