Awesome PHP has been relocated permanently to its own Github repository. No further updates will made to this gist.
Please open an issue for any new suggestions.
| <?php | |
| /* | |
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| <?php | |
| $countries = array | |
| ( | |
| 'AF' => 'Afghanistan', | |
| 'AX' => 'Aland Islands', | |
| 'AL' => 'Albania', | |
| 'DZ' => 'Algeria', | |
| 'AS' => 'American Samoa', | |
| 'AD' => 'Andorra', |
| // See http://rosskendall.com/blog/web/javascript-function-to-check-an-email-address-conforms-to-rfc822 | |
| function isEmail(email){ | |
| return /^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*$/.test( email ); | |
| } |
| <?php | |
| // Add social proof numbers to footer (repositioned to top of page via CSS) | |
| function add_social_proof() { ?> | |
| <div id="social-proof"> | |
| <ul> | |
| <li class="facebook"><a href="YOUR_FACEBOOK_PAGE_URL" target="_blank" title="Disrupting the Rabblement on Facebook"><?php facebook_fan_count() ?> Fans</a></li> | |
| <li class="twitter"><a href="YOUR_TWITTER_PROFILE_URL" target="_blank" title="Follow Niall on Twitter"><?php twitter_follower_count() ?> Followers</a></li> | |
| <li class="email"><a href="YOUR_SUBSCRIBER_FORM_URL" target="_blank" title="Subscribe to email updates"><?php subscriber_count() ?> Subscribers</a></li> | |
| </ul> | |
| </div> |
| <?php # -*- coding: utf-8 -*- | |
| /** | |
| * Plugin Name: Defer Contact Form 7 Scripts | |
| * Description: Adds <code>defer='defer'</code> to enqueued javascripts. | |
| * Version: 1.0 | |
| * Required: 3.3 | |
| * Author: Fuxia Scholz | |
| * Author URI: https://fuxia.me | |
| * License: GPL | |
| * License URI: http://www.gnu.org/copyleft/gpl.html |
| DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
| Version 2, December 2004 | |
| Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE> | |
| Everyone is permitted to copy and distribute verbatim or modified | |
| copies of this license document, and changing it is allowed as long | |
| as the name is changed. | |
| DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE |
Awesome PHP has been relocated permanently to its own Github repository. No further updates will made to this gist.
Please open an issue for any new suggestions.
=====
I made a book, its one page.
| <?php | |
| $lines = explode( "\n", file_get_contents( 'input.csv' ) ); | |
| $headers = str_getcsv( array_shift( $lines ) ); | |
| $data = array(); | |
| foreach ( $lines as $line ) { | |
| $row = array(); | |
| foreach ( str_getcsv( $line ) as $key => $field ) |
| class ModelAdmin extend Admin | |
| { | |
| // ... | |
| public function validate(ErrorElement $errorElement, $object) | |
| { | |
| // find object with the same uniqueField-value | |
| $other = $this->modelManager->findOneBy($this->getClass(), array('uniqueField' => $object->getUniqueSlug())); | |
| if (null !== $other && !$other->equals($object)) { |