Skip to content

Instantly share code, notes, and snippets.

View long-getters-and-setters.php
<?php
class Song {
private $duration;
private $name;
//Getters/Setters
function setName( $name ) {
return $this->name;
}
View address-array.php
<?php
$address = array(
'name' => 'John Smith',
'line1' => '1 Somewhere Road',
'line2' => 'Happytown',
'region' => 'Somewhere County',
'country' => 'United Kingstates'
'postcode' => '123 ABC'
);
View address-object.php
<?php
$address = new Address();
$address->name = 'John Smith';
$address->line2 = ... etc
View fizzbuzz.rb
(1..100).each do |i|
print "Fizz" if i % 3 == 0
print "Buzz" if i % 5 == 0
print i.to_s unless i % 3 == 0 or i % 5 == 0
print "\n"
end
View render.php
<?php
function render($page, $params = array()) {
extract($params);
include "{$page}.php";
}
View layout.php
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' type='text/css' href='style.css' media='screen' />
<script type='text/javascript' src='jquery.js'></script>
<title>Alis Fruity Milkshakes</title>
</head>
<body>
<div id='wrapper'>
<div id='header'>
View page.php
<h3><?= $title ?></h3>
<div id='content'>
<?= $content ?>
</div>
View render_page.php
<?php
function render_page($page, $params = array(), $layout = 'layout') {
extract($params);
$__page = "{$page}.php";
include "{$layout}.php";
}
View render_page_example.php
<?php
//calling this with the above files (layout.php + page.php) in the working directory
render_page('page', array(
'title' => "About The Shakes",
'content' => "<p>Bringing the boys to the yard since 1976</p>"
));
//would then render this =>
View sidebar.html
<ul>
<li>
<a href='/home.php'>Home</a>
</li>
<li>
<a href='/about.php'>About</a>
</li>
<li>
<a href='/contact.php'>Contact</a>
</li>