プロが教えるわが家の防犯対策術!

PHPで読み込むファイルによってtitleタグ変更したいのですが・・・

ショッピングのサイトです。
現在商品ページ(info.php)では商品の項目をtitleタグに反映できるのですが、カテゴリページ(search.php)用にこれを変更して使用したいです。

商品ページ用のphpは

----------------------------------------------------------------------------------
/*商品詳細ページのタイトルなら、商品名等を追記する。*/
if( 'item' == $_GET[ 'type' ] && preg_match( '/\/info.php$/' , $_SERVER[ 'SCRIPT_NAME' ] ) )
{
 $iDB = $tgm[ 'item' ]->getDB();
 $iTable = $iDB->searchTable( $iDB->getTable() , 'id' , '=' , $_GET[ 'id' ] );

 $categorys = Array();

  if( $iDB->getRow( $iTable ) )
  {
   /*商品情報*/
   $iRec = $iDB->getRecord( $iTable , 0 );
   $itemName = $iDB->getData( $iRec , 'name' );
   $parentIDs = explode( '/' , $iDB->getData( $iRec , 'parent' ) );
   $childIDs = explode( '/' , $iDB->getData( $iRec , 'child' ) );

   /*親カテゴリ情報*/
   $cDB = $tgm[ 'parentCategory' ]->getDB();
   $cTable = $cDB->searchTable( $cDB->getTable() , 'id' , 'in' , $parentIDs );

    for( $i = 0 ; $i < $cDB->getRow( $cTable ) ; $i++ )
     {
     $cRec = $cDB->getRecord( $cTable , $i );
     $parentID = $cDB->getData( $cRec , 'id' );
     $category = $cDB->getData( $cRec , 'name' );

     *子カテゴリ情報*/
     $chDB = $tgm[ 'childCategory' ]->getDB();
     $chTable = $chDB->searchTable( $chDB->getTable() , 'id' , 'in' , $childIDs );
     $chTable = $chDB->searchTable( $chTable , 'parent' , '=' , $parentID );

      for( $j = 0 ; $j < $chDB->getRow( $chTable ) ; $j++ )
       { 
        $chRec = $chDB->getRecord( $chTable , $j );
        $category .= ' : ' . $chDB->getData( $chRec , 'name' );
}

        $categorys[] = $category;
}
}
        $title = $itemName .'' . '[' . implode( '][' , $categorys ) . ']' .'' . $title;
}


----------------------------------------------------------------------------------
親カテゴリページのときは親カテゴリを子カテゴリページの時は子カテゴリをタイトルにしたいのですが、phpは素人の為分からないのです。

ご教授願えればと思います。
よろしくお願いします。

A 回答 (1件)

どういう動作なのかがうまく掴めなかったので、


とりあえず、あるページのタイトルタグの内容を取得する関数を書いておきます。

function gettitle($url)
{
$data = file_get_contents($url);
preg_match_all('@<title(.*?)>(.*?)</title>@i', $data, $title);
return $title[2][0];
}

引数にはタイトルを取得したいページの絶対パスを渡してください。


見当違いの内容でしたらすみません。
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!