Last active
December 15, 2015 06:49
-
-
Save tsmsogn/5218600 to your computer and use it in GitHub Desktop.
[php]Snippets
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 | |
| class Foo { | |
| var $bar; | |
| var $baz; | |
| function Foo($options = array()) { | |
| if (!empty($options)) { | |
| $this->setOptions($options); | |
| } | |
| } | |
| function setOptions($options = array()) { | |
| if (is_array($options) && !empty($options)) { | |
| $fields = array_keys(get_object_vars($this)); | |
| foreach ($options as $key => $value) { | |
| if (in_array($key, $fields)) { | |
| $this->$key = $value; | |
| } | |
| } | |
| } | |
| } | |
| } |
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
| number_format(floor($sum - ($sum / 1.05))); |
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 | |
| $handle = fopen($fileName, 'rb'); | |
| while (!feof($handle)) { | |
| echo fread($handle, 4096); | |
| // 4Kずつ読み込んで書きだす | |
| ob_flush(); | |
| flush(); | |
| } | |
| fclose($handle); |
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 filter_for_image_the_content($content) { | |
| $pattern = '/<img(?:[^>"\']*|"[^"]*"|\'[^\']*\')*\ssrc=("|\')(.*?)\1(?:[^>"\']*|"[^"]*"|\'[^\']*\')*>/si'; | |
| preg_match_all($pattern, $content, $tagMatches); | |
| for ($i=0; $i < count($tagMatches[1]); $i++) { | |
| $tag = '<a href="'.$tagMatches[2][$i].'" target="_blank">Image</a>'; | |
| //$tag = 'Image'; | |
| $content = str_replace($tagMatches[0][$i], $tag, $content); | |
| } | |
| return $content; | |
| } | |
| add_filter('the_content', 'filter_for_image_the_content', 9); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment