最初の要素で配列を作る必要性を教えてください - PHPプロ!Q&A掲示板
キーワード / キーワードが設定されていません
- error_reporting(1);
- require('XMLLibrary.php');
- $data = file_get_contents("http://www.google.com/calendar/feeds/1qkkqtv5eo3jimiidbltonpi1s%40group.calendar.google.com/public/basic");
- $array = XML_unserialize($data);
- $entry = $array['feed']['entry'];
- $today = date("Y/m/d");
- // 最初の要素で配列を作る
- $datas = array();
- // ここから
- $tlong = strlen($entry[0]['title']);
- if($tlong>38){$entry[0]['title']=mb_strimwidth($entry[0]['title'],0,37);
- $cont[0]['title'] = $entry[0]['title']." ...";
- }else $cont[0]['title'] = $entry[0]['title'];
- $cont[0]['content'] = mb_strimwidth($entry[0]['summary'],3,30);
- $datas[0] = $cont[0]['content'];
- $cont[0]['link'] = $entry[0]['link']['0 attr']['href'];
- // ↑ここまでの必要性が理解できません…。
- print "最初の要素<br />";
- print_r ($datas)."<br/>";
- echo "<br/>";
- print_r ($cont)."<br/>";
- print "<br />";
- print "エントリーの要素の数<br />";
- $count = count($entry);
- print($count);
- for($i=1; $i<$count; $i++){
- $tlong = strlen($entry[$i]['title']);
- if($tlong>38){$entry[$i]['title'] = mb_strimwidth($entry[$i]['title'],0,37);
- $cont[$i]['title'] = $entry[$i]['title']." ...";
- }else $cont[$i]['title'] = $entry[$i]['title'];
- $cont[$i]['content']=mb_strimwidth($entry[$i]['summary'],3,30);
- array_push($datas,$cont[$i]['content']);
- $cont[$i]['link'] = $entry[$i]['link']['0 attr']['href'];
- }
- print "<br />";
- print "配列の一覧<br />";
- print_r ($datas)."<br/>";
- echo "<br/>";
- print_r ($cont)."<br/>";
- foreach($datas as $i => $s) {
- if (strtotime($s) < strtotime($today)) {
- /* 配列から削除する */
- unset($datas[$i]);
- }
- }
- asort( $datas );//日付でならべかえる
- $nub = count($datas);//7つまで表示したい
- if ($nub>=7){$a = $nub-7;
- unset($datas[$a]);
- }
- foreach ($datas as $key => $value) {
- print <<<ENTRY_PEINT
- <p class="m"><a href="#" onclick="window.open('{$cont[$key][ 'link' ]}','javascript_1','height=250,width=700,resizable');">{$cont[$key]['title']}</a></p><p class="s">{$cont[$key]['content']}…</p></p>\n
- ENTRY_PEINT;
- }
みごとできたのですが、
http://www.actionk.co.jp/gcalender1.php
私の頭の中では、どうして最初の要素を使って配列に入れる必要があるのかが理解できないんです。
これを消すと うまく並ばないのが納得いきません。
ほとんど同じなので… 毎度不思議な質問ですみません。 いきなり全部格納なぜできなんでしょうか?
この質問への意見の募集は締め切られ、ポイントは既に配分されました。
意見を投稿することはできますが、ポイントを受け取ることはできません。




ページのトップへ


GETのままでは検索エンジンのロボットが拾ってくれなかったためにSEO対策として有効だと言われていますね。