Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
phpfiddle / chart_3dpie.php
Created September 9, 2012 03:46
Create a 3D pie chart with GD library
<?php
/**
* 3D pie chart with GD library
*
**/
// Create an image
$image = imagecreatetruecolor(100, 100);
// Allocate some colors
@phpfiddle
phpfiddle / stream_filter.php
Last active October 10, 2015 12:38
User defined stream filter sample
<?php
/**
* User defined stream filter sample
* Source: http://php.net/manual/pt_BR/function.stream-filter-register.php
**/
class string_filter extends php_user_filter
{
function filter($in, $out, &$consumed, $closing)
{
@phpfiddle
phpfiddle / spl_sample.php
Created September 10, 2012 18:43
SPL Sample
<?php
/**
* SPL Sample
*
*/
$file = new SplFileObject(__FILE__);
foreach ($file as $line)
{
@phpfiddle
phpfiddle / file_sock.php
Created September 10, 2012 19:01
Using file socket to read a page
<?php
/**
* Using file socket to read a page
* Sample from internet
*/
$fp = fsockopen ("slashdot.org", 80);
@phpfiddle
phpfiddle / sample06_1.php
Last active November 7, 2023 14:01
PHP, PDO and SQLite2 example
<?php
/**
* PHP, PDO and SQLite2 example
* The code got from Internet
*
*/
// Set default timezone
date_default_timezone_set('UTC');
@phpfiddle
phpfiddle / fiddle_365999.php
Created March 26, 2013 21:18
PHP DOM Sample.
<?php
function innerHTML($el) {
$doc = new DOMDocument();
$doc->appendChild($doc->importNode($el, TRUE));
$html = trim($doc->saveHTML());
$tag = $el->nodeName;
return preg_replace('@^<' . $tag . '[^>]*>|</' . $tag . '>$@', '', $html);
}
@phpfiddle
phpfiddle / 19c763e8e5d37d254c5f98549b3ddb64.php
Created March 26, 2013 22:42
[ Posted by Fiddler ] XSLT transformation Demo.
<?php
/* XSLT transformations */
$owner = "PhpFiddle";
$collection_xsl = <<<DOC
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="owner" select="'Nicolas Eliaszewicz'"/>
<xsl:output method="html" encoding="iso-8859-1" indent="no"/>
<xsl:template match="collection">
@phpfiddle
phpfiddle / fiddle_503425.php
Created March 27, 2013 10:07
simple form state
<?php
$_POST['kelas'] = isset($_POST['kelas']) ? $_POST['kelas'] : 0; // this line removes notices (ignore this)
$_POST['tahun'] = isset($_POST['tahun']) ? $_POST['tahun'] : 0; // this line removes notices (ignore this)
?>
<form method='post'>
<select name='kelas'>
<option value=0>Pilih kelas</option>
<option value=1 <?php if($_POST['kelas']==1) echo 'selected' ?> >X-1</option>
<option value=2 <?php if($_POST['kelas']==2) echo 'selected' ?> >X-2</option>
@phpfiddle
phpfiddle / fiddle_178586.php
Created March 27, 2013 10:30
Simple export excel
<?php
$html = '<table border=1>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
@phpfiddle
phpfiddle / 60504c75bff7ffd941cd23196224c1c8.php
Created March 27, 2013 22:47
[ Posted by Richard ] php print color.
<?php
/* My Color */
$today = date("w");
$bgcolor = array
(
"#FEF0C5", "#FFFFFF", "#FBFFC4", "#FFE0DD",
"#E6EDFF", "#E9FFE6", "#F0F4F1"
);