A parallax effect purely done in CSS, taken from: http://blog.keithclark.co.uk/pure-css-parallax-websites/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function long_datetime($datetime, $level = 7) { | |
| $now = new DateTime; | |
| $datetime = new DateTime($datetime); | |
| $suffix = $now > $datetime ? ' ago' : ' ahead'; | |
| $diff = $now->diff($dt); | |
| $diff->w = floor($diff->d / 7); | |
| $diff->d -= $diff->w * 7; | |
| $formats = [ | |
| 'y' => ' year', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function xsd_to_json($xsd_file, $formatted = 448) { | |
| $xml_file = preg_replace('/\.xsd$/', '.xml', $xsd_file); | |
| $json_file = preg_replace('/\.xsd$/', '.json', $xsd_file); | |
| $doc = new DOMDocument(); | |
| $doc->preserveWhiteSpace = true; | |
| $doc->load($xsd_file); | |
| $doc->save($xml_file); | |
| $xml = file_get_contents($xml_file); | |
| $obj = str_replace($doc->lastChild->prefix.':', "", $xml); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function xml_to_array($xml) { | |
| return json_decode(str_replace(['{}', '"NULL"'], ['""', 'null'], json_encode(simplexml_load_string($xml))), TRUE); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Invalid end tag </s> | |
| $html = <<<HTML | |
| <table> | |
| <tr> | |
| <td>123</s></td> | |
| <td>456</td> | |
| </tr> | |
| </table> | |
| HTML; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function xml_to_json($xml, $formatted=TRUE) { | |
| $options = (bool)$formatted ? JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE : 0; | |
| return json_encode(simplexml_load_string($xml), $options); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function format_xml($xml, $formatOutput=TRUE, $declaration=TRUE) { | |
| $sxe = ($xml instanceof \SimpleXMLElement) ? $xml : simplexml_load_string($xml); | |
| $domElement = dom_import_simplexml($sxe); | |
| $domDocument = $domElement->ownerDocument; | |
| $domDocument->preserveWhiteSpace = false; | |
| $domDocument->formatOutput = (bool)$formatOutput; | |
| $domDocument->loadXML($sxe->asXML(), LIBXML_NOBLANKS); // Fixes newlines omitted by DomNode::appendChild() | |
| return (bool)$declaration ? $domDocument->saveXML() : $domDocument->saveXML($domDocument->documentElement); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Get array entries that match pattern in their keys. | |
| * | |
| * @link https://www.php.net/manual/en/function.preg-grep.php | |
| * @param string $pattern | |
| * @param array $assoc | |
| * @param int $flags 0 or PREG_GREP_INVERT | |
| * @return array | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class String | |
| def p(**args) | |
| gsub(/:[\w]*/){|match| args[match[1..-1].to_sym] || match} | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class String | |
| def filter_html_attribute(attribute_key, args={}) | |
| self.gsub!(/#{attribute_key}="([^"]*)"/) do |attribute| | |
| return "" if attribute.nil? | |
| attribute_value = $1.split(args[:split]).delete_if {|i| i.match(args[:match]) }.join(args[:join]) | |
| attribute_value += args[:append].to_s unless attribute_value.empty? | |
| attribute.replace("#{attribute_key}=\"#{attribute_value}\"") | |
| end | |
| self.gsub!(/ (#{attribute_key})=""/, "") | |
| end |