いずれ役に立ちそうな PHPからJavaScriptに変数を渡すまとめ

http://qiita.com/cither/items/b98cc4e237dcc8f7e51f

<?php
    $array = array("hoge" => "fuga");
?>
<script>
    var array = <?php echo json_encode($array, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT); ?>;
    console.log(array); // Object { hoge: "fuga" }
</script>
function json_safe_encode($data){
    return json_encode($data, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT);
}
<?php
    $null        = null;
    $string      = "hoge";
    $emptyString = "";
    $array       = array("hoge", "fuga");
    $empty_array = array();
    $asoc_array  = array("hoge" => 1, "fuga" => 2);
    $boolean     = false;
    $str_boolean = "false";
    $zero        = 0;
    $str_zero    = "0";
    $float       = 0.12;
?>
<script id="script" src="script.js"
    data-null         ='<?php echo json_safe_encode($null); ?>'
    data-string       ='<?php echo json_safe_encode($string); ?>'
    data-empty-string ='<?php echo json_safe_encode($empty_string); ?>'
    data-array        ='<?php echo json_safe_encode($array); ?>'
    data-empty-array  ='<?php echo json_safe_encode($empty_array); ?>'
    data-asoc-array   ='<?php echo json_safe_encode($asoc_array); ?>'
    data-boolean      ='<?php echo json_safe_encode($boolean); ?>'
    data-str-boolean  ='<?php echo json_safe_encode($str_boolean); ?>'
    data-zero         ='<?php echo json_safe_encode($zero); ?>'
    data-str-zero     ='<?php echo json_safe_encode($str_zero); ?>'
    data-float        ='<?php echo json_safe_encode($float); ?>'
></script>
var $script     = $('#script');
var _null       = JSON.parse($script.attr('data-null'));
var string      = JSON.parse($script.attr('data-string'));
var emptyString = JSON.parse($script.attr('data-empty-string'));
var array       = JSON.parse($script.attr('data-array'));
var emptyArray  = JSON.parse($script.attr('data-empty-array'));
var asocArray   = JSON.parse($script.attr('data-asoc-array'));
var boolean     = JSON.parse($script.attr('data-boolean'));
var strBoolean  = JSON.parse($script.attr('data-str-boolean'));
var zero        = JSON.parse($script.attr('data-zero'));
var strZero     = JSON.parse($script.attr('data-str-zero'));
var float       = JSON.parse($script.attr('data-float'));


console.log(_null);       // null
console.log(string);      // "hoge"
console.log(emptyString); // ""
console.log(array);       // Array [ "hoge", "fuga" ]
console.log(emptyArray);  // Array [  ]
console.log(asocArray);   // Object { hoge: 1, fuga: 2 }
console.log(boolean);     // false
console.log(strBoolean);  // "false"
console.log(zero);        // 0
console.log(strZero);     // "0"
console.log(float);       // 0.12

複数全角スペースを1個に置き換えて 改行を全角スペース2こに変換して表示

<?php $ryoukin = preg_replace("/[ ]+/u"," ",get_post_meta($post->ID,料金,true)); 
 $ryoukin =str_replace("\r\n", '  ', $ryoukin);
 echo $ryoukin;?>

さんこう
http://oshiete.goo.ne.jp/qa/2138841.html
http://fdays.blogspot.jp/2008/02/pregreplace.html
http://www.koikikukan.com/archives/2013/07/12-011111.php
http://php.net/manual/ja/function.nl2br.php

05naviの記事件数 登録 何件?

ファンクションへ
オリジナル関数だと思う

//特定のカテゴリと特定のタグで絞った記事数の表示方法
function taxonomy_found_posts_num() {
    $args = array(
'post_type' => array('shoku','asobu','share','seikatsu','iryou','manabu','koukyou','ofuroyado'), //カスタム投稿名
    );
    $my_query = new WP_Query($args);
    return $my_query->found_posts;
}

//表示箇所に
//<?php echo taxonomy_found_posts_num('hokkaido','タグ1'); 件<br />
//<?php echo taxonomy_found_posts_num('aomori','タグ2'); 件

上記正式コード

<?php
function taxonomy_found_posts_num($cat_slug,$tag_slug) {
    $args = array(
        'post_type' =>'post',
        'tax_query' => array(
            'relation' => 'AND',
            array(
                'taxonomy' => 'category',
                'field' => 'slug',
                'terms' => $cat_slug,
            ),
            array(
                'taxonomy' => 'post_tag',
                'field' => 'slug',
                'terms' => $tag_slug,
            ),
        ),
        'posts_per_page' => 1
    );
    $my_query = new WP_Query($args);
    return $my_query->found_posts;
}
?>
    <?php 

//特定のポストタイプと特定のユーザーIDで絞った記事数の表示方法
function taxonomy_found_posts_num1($post_type,$user_id) {
    $args = array(
'post_type' => $post_type, //カスタム投稿名
'author' => $user_id,
    );
    $my_query = new WP_Query($args);
    return $my_query->found_posts;
}

//ログインユーザーのIDを取得
$user = wp_get_current_user();
$user_idd = $user->get('ID')."\n"; // ID

//出力
echo taxonomy_found_posts_num1('shoku',$user_idd);
	?>

アロー演算子

codeigniterでDBアクセス時に用いるもの

http://codeigniter.jp/user_guide_ja/database/examples.html

$query = $this->db->query('SELECT name, title, email FROM my_table');

foreach ($query->result() as $row)
{
    echo $row->title;
    echo $row->name;
    echo $row->email;
}

echo 'Total Results: ' . $query->num_rows();