Skip to content

Instantly share code, notes, and snippets.

@tsmsogn
Last active December 15, 2015 06:49
Show Gist options
  • Select an option

  • Save tsmsogn/5218600 to your computer and use it in GitHub Desktop.

Select an option

Save tsmsogn/5218600 to your computer and use it in GitHub Desktop.
[php]Snippets
<?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;
}
}
}
}
}
number_format(floor($sum - ($sum / 1.05)));
<?php
$handle = fopen($fileName, 'rb');
while (!feof($handle)) {
echo fread($handle, 4096);
// 4Kずつ読み込んで書きだす
ob_flush();
flush();
}
fclose($handle);
<?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