<article class="woman">
<h3>
<a href="http://en.wikipedia.org/wiki/Ada_Lovelace">Ada Lovelace</a>
</h3>
<h4>(1815–1852)</h4>
<img src="images/ada_lovelace.jpg" alt="Ada Lovelace" />
<p>An analyst of Charles Babbage's analytical engine and is often
described as the "first computer programmer."</p>
</article>
<article class="woman">
<h3>
<a href="http://en.wikipedia.org/wiki/Grace_Hopper">Grace Hopper</a>
</h3>
<h4>(1906–1992)</h4>
<img src="images/grace_hopper.jpg" alt ="Grace Hopper" />
<p>A United States Navy officer and the first programmer of the
Harvard Mark I, known as the "Mother of COBOL". She developed the
first ever compiler for an electronic computer, known as A-0.</p>
</article>
<section id="famous">
<a name="famous"></a>
<h2>Famous Women</h2>
<a class="jump up" href="#">ì</a>
<a class="jump down" href="#organizations">í</a>
<div class = "wrapper">
<?php echo viewWoman('Ada Lovelace',
'http://en.wikipedia.org/wiki/Ada_Lovelace',
'(1815–1852)',
'images/ada_lovelace.jpg',
'An analyst of Charles Babbage\'s analytical engine and is often
described as the "first computer programmer."'); ?>
<?php echo viewWoman('Grace Hopper',
'http://en.wikipedia.org/wiki/Grace_Hopper',
'(1906–1992)',
'images/grace_hopper.jpg',
'A United States Navy officer and the first programmer of the
Harvard Mark I, known as the "Mother of COBOL". She developed the
first ever compiler for an electronic computer, known as A-0.'); ?>
</div>
</section>
<?php
function viewWoman($name, $url, $years_lived, $image_url, $biography)
{
return '<article class="woman">
<h3><a href="' . $url . '">' . $name . '</a></h3>
<h4>' . $years_lived . '</h4>
<img src="' . $image_url . '" alt="' . $name . '" />
<p>' . $biography . '</p>
</article>';
}
<?php
$class = 'Girl Develop It';
function WhereAmI($class){
return 'I am in the ' . $class . ' class.';
}
echo WhereAmI($class); // I am in the Girl Develop It class.
echo WhereAmI('Math'); // I am in the Math class.
echo WhereAmI(); // Error
<?php
function WhereAmI($class, $location = 'Detroit'){
$using = 'a computer;
return 'I am in the ' . $class . ' class in ' . $location . ', using ' . $using . '.';
}
echo WhereAmI($class); // I am in the Girl Develop It class in Detroit, using a computer.
<?php
$global_variable = 'Some data';
function MyFunction($argument1, $argument2) {
$local_variable = $argument1 + $argument2;
return $local_variable;
}
function my_func($arg1,$arg2) {
<< function statements >>
return $value;
}
<?php
class Dog {
public $name;
public function bark() {
echo 'Woof!';}
}
}
<?php
require_once(‘dog.class.php’);
$puppy = new Dog();
$puppy->name = 'Rover';
echo "{$puppy->name} says ";
$puppy->bark();
<?php
class Poodle extends Dog {
public $type
public function set_type($height)
{
if ( $height < 10 )
{
$this->type = ‘Toy’;
}
elseif ( $height > 15 )
{
$this->type = ‘Standard’;
}
else
{
$this->type = ‘Miniature’;
}
}
}
<?php
$puppy = new poodle(‘Oscar’);
$puppy->set_type(12); // 12 inches high!
echo “Poodle is called {$puppy->name}, ”;
echo “of type {$puppy->type}, saying “;
echo $puppy->bark();
…
<?php
class Dog {
...
public function bark() {
echo 'Woof!';}
}
}
<?php
class Poodle extends Dog {
...
public function bark() {
echo ‘Yip!’;
}
}
<?php unset($puppy);
?>
<?php
// Some class included with a framework
class File {
...
}
<?php
// Your local file class
class File {
...
}
$myFile = new File; // Problem
<?php
// Some class included with a framework
class File {
...
}
<?php
// Your local file class
namespace Acme;
class File {
...
}
$myFile = new Acme\File; // Your local File class
$theirFile = new \File; // The framework File class
<?php
// Turn off all error reporting
error_reporting(0);
// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
// Report all errors except E_NOTICE
error_reporting(E_ALL ^ E_NOTICE);
// Report ALL PHP errors
error_reporting(E_ALL);
?>
<?php
/* Intentional file error */
$my_file = @file ('non_existent_file') or
die ("Failed opening file: error was '$php_errormsg'");
<?php
try {
if ( ($fp = @fopen($filename, "r")) == false)
{
throw new Exception;
}
do_file_stuff($fp);
} catch (Exception $e) {
handle_exception();
}
<?php
Exception {
/* Properties */
protected string $message ;
protected int $code ;
protected string $file ;
protected int $line ;
/* Methods */
public __construct ([ string $message = "" [, int $code = 0 [, Exception $previous = NULL ]]] )
public string getMessage ( void )
public Exception getPrevious ( void )
public mixed getCode ( void )
public string getFile ( void )
public int getLine ( void )
public array getTrace ( void )
public string getTraceAsString ( void )
public string __toString ( void )
private void __clone ( void )
}
<form method="get" action="search.php">
...
</form>
<input type="text" name="first_name">
<textarea name="comment" id="comment" cols="50" rows="4">
<input type="submit" name="submit" id="submit-button" value="Submit" />
<?php
// Do search
if ( isset($_GET['q']) )
{
$results = DoSearch($_GET['q']);
}
...
<form method="get" action="search.php">
<label for="q">Search</label>
<input type="input" name="q" id="q" value="" />
<input type="submit" value="Search" />
</form>
<section class="results">
<?php
echo '<p>Results for: ' . $_GET['q'] . '</p>';
foreach ( $results as $result )
{
ViewResult($result);
}
?>
<?php
$search_term = filter_input(INPUT_GET, 'q', FILTER_SANITIZE_SPECIAL_CHARS);
?>
<script>alert('Xss');</script>
<script>alert('Xss');</script>
<?php
// If trying to search
if ( isset($_GET['q']) )
{
$search_term = filter_input(INPUT_GET, 'q', FILTER_SANITIZE_SPECIAL_CHARS);
if ( is_array($women) )
{
foreach ($women as $woman)
{
if ( stristr($women['name'], $search_term) )
{
$results[] = $women;
}
}
}
}
<?php if ( isset($search_term) ) { ?>
<section class="results">
<p>Results for: <?php echo $search_term; ?></p>
<?php
foreach ($results as $woman)
{
echo viewWoman($woman['name'], $woman['link'], $woman['years'], $woman['image'], $woman['biography']);
}
?>
</section>
<?php } ?>
<?php
$clean = array();
if (ctype_alnum($_POST['username']))
{
$clean['username'] = $_POST['username'];
}