公開日 2018.3.22更新日 2022.10.27カテゴリ:Laravelタグ:PHP,Laravel,QueryBuilder
PHPのjson_decodeは値が " (ダブルコーテーションで)囲まれていないと null になるっぽい。 json_decode() でnull になるJSONのパターン 1. " で囲われていない値がある json = {1: "星宮いちご"} <?php json_decode( json ); // => NULL 2. 値が ' (シングルコーテーション)で囲まれている json = {"1": '<b class="idol">星宮いちご</b>'} <?php json_decode( json ); // => NULL ` ←コレもダメ json = {"1": `星宮いちご`} <?php json_decode( json ); // => NULL 3. 行末に , がある json = {"1": "星宮いちご",} <?php json_decode( js
はじめに Laravel5.1やってて自分なりに思ったこと、気づいたことなんかをまとめてみました。 随時追加していきます。 5.5触ってみたいけどそんな余裕ない。 Model関係 \App\Model->get()で取得カラムを指定する
PHPのerror_log()関数でApacheのエラーログ等に日本語のメッセージを吐き出すと \xe8\xaa\x8d\xe8\xa8\xbc\xe3\x81\xab\xe5\xa4\xb1\xe6\x95\x97\xe3\x81\x97\xe3\x81\xbe\xe3\x81\x97\xe3\x81\x9f\xe3\x80\x82といった感じに文字化けして出てくる時がある。 まぁ厳密には文字化けしている訳ではなくて、セキュリティの観点から適切にエスケープ処理してくれているだけなんだけど、デバッグ中の身としては余計なお世話だったりする。 (^^; Apacheの環境設定をいじるとエスケープされなくなるようだけど、お客さんのとこの環境を勝手に変える訳に行かなかったり、他の表示に影響が出る場合があるのであまり環境設定をいじりたくない。 とりあえずプログラムでエスケープされた文字を復元したりし
コード中、処理時間がかかってる箇所を探す関数です。 コード中にちりばめれば、どの行間で時間かかってるか確認できます。 function debug_time(){ $debug = current(debug_backtrace()); static $start_time = 0; static $pre_debug = null; static $pre_time = 0; $time = microtime(true); if(!$start_time) $start_time = $time; if($pre_time){ echo sprintf('<div>[%s(%d) - %s(%d)]: %d ms(ttl:%d ms)</div>', basename($pre_debug['file']), $pre_debug['line'], basename($debug['f
您的请求在Web服务器中没有找到对应的站点! 可能原因: 您没有将此域名或IP绑定到对应站点! 配置文件未生效! 如何解决: 检查是否已经绑定到对应站点,若确认已绑定,请尝试重载Web服务; 检查端口是否正确; 若您使用了CDN产品,请尝试清除CDN缓存; 普通网站访客,请联系网站管理员;
明示的 意味 แพลตฟอร์มการเรียนรู้และพัฒนาทักษะด้วยเทคโนโลยี https://suin.io เป็นแพลตฟอร์มที่ให้คุณเรียนรู้และพัฒนาทักษะทางเทคโนโลยีอย่างสะดวกสบาย เรามุ่งมั่นในการให้ความรู้และประสบการณ์ที่มีคุณค่าในการพัฒนาตนเอง pascalcase
一手間必要なPHPでのSimpleXML関数のパース処理 今回はPHPによるXMLデータのパース処理で気になったので、 それについての小ネタです。 まずは基本 PHP5でXMLデータを簡単にオブジェクト化してくれる 「SimpleXML」関数を利用します。 例えば simplexml_load_file() simplexml_load_string() 関数自体の細かい説明は省きますが、「simplexml_load_file()」は XMLファイルからXMLデータを読みだしてオブジェクト化し、 「simplexml_load_string()」は形成されたXML文字列をオブジェクト化する なんとも便利な関数です。 こんな感じに $xml = simplexml_load_file('xml.xml'); print($xml); 結果 SimpleXMLElement Object (
XMLデータはPHPのsimplexml_load_file()関数などを用いる事で扱いが簡単になりますが、普通に使用すると「@(アットマーク)attributes」以下のデータが取得できません。 「@attributes」内のデータを取得する方法は以下から。 下記の様なXMLデータがあるとします。 <?xml version="1.0" encoding="UTF-8" ?> <xmldata> <test>test</test> <hoge data01="aaaa" data02="bbbb"> <moge data03="cccc" data04="dddd" /> </hoge> </xmldata> 上記XMLをPHPのsimplexml_load_file()関数で読み込むと、下記の様なデータ形式で取得できます。 object(SimpleXMLElement)#1 (2)
本日からPHPのメモを記述して行こうと思います。 さて早速今日のネタ。 ぎじゅっやさんにてfile_get_contentsでWebページへアクセスする際に、UserAgentを変更する方法が紹介されています。 では、これを応用してfile_get_contentsを使ってPOST形式でデータを送信してみましょう。 参考コード <?php //POSTデータ $data = array( "param1" => "data1", "param2" => "data2" ); $data = http_build_query($data, "", "&"); //header $header = array( "Content-Type: application/x-www-form-urlencoded", "Content-Length: ".strlen($data) ); $cont
「追記とか」にコメントの返答や追記をしてますので合わせてどうぞ。 かれこれ3年くらいPHPをやっているので、せっかくなので10個の便利な関数を並べてみました。 作業効率がかなりアップするので、これからPHPをやってみようかなぁって思う方は知っておくと便利だと思います。 変数、配列の内容をキレイに表示する関数「d」 変数や配列の内容をHTML構文でキレイに表示してくれます。 しかも、var_dumpと書くとタイピングが大変なので「d($hoge)」として簡単に記述。 これだけでも作業効率8倍 function d() { echo '<pre style="background:#fff;color:#333;border:1px solid #ccc;margin:2px;padding:4px;font-family:monospace;font-size:12px">'; foreac
■ PHP の switch 文は怖くて使えない PHP の == 演算子が地雷なのは知っていましたが、 まさか switch 文にも同じ問題があるとは思いませんでした。 これでピンと来ない人は、先に以下のページでも読んで下さい。 PHP が落とし穴だらけの言語であることが分かります。 素晴らしき自動的な世界〜或いは「型のない」世界〜 - がるの健忘録 さて、私が今回はまりそうになったのはこういうコードです。 function filter($value) { switch ($value) { case 'abc': case 'def': return $value; break; default: return ''; break; } } 要するに、入力値として abc と def だけ受け付けようという意図なんですが、 このコードにはバグがありまして、 php > echo fi
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く