html - PHP Array not correctly pulling data from php file -


i'm bit stuck on code. worked "before" on different site reason not work new 1 working on. have separate php file store meta title, meta description, meta keywords, h1, h2 tags in array. website supposed fetch information divy variables , placed in correct positions within code. here code follows:

seo.php file in root folder of website

        <?php        $meta['index']['title']            = "title";        $meta['index']['keywords']         = "keywords";        $meta['index']['description']      = "description";        $meta['index']['h1']            = "h1";        $meta['index']['h2']            = "h2";         $meta['about']['title']            = "about company";        $meta['about']['keywords']         = "kwd1, kwd2, kwd3";        $meta['about']['description']      = "about company description";        $meta['about']['h1']            = "h1 title";         $meta['services']['title']         = "about company";        $meta['services']['keywords']      = "kwd1, kwd2, kwd3";        $meta['services']['description']   = "about company description";        $meta['services']['h1']             = "h1 title";         $meta['blog']['title']              = "about company";        $meta['blog']['keywords']           = "kwd1, kwd2, kwd3";        $meta['blog']['description']       = "about company description";        $meta['blog']['h1']                 = "h1 title";      ?> 

example of code in index.php

    <?php        include 'seo.php';        $page_index = array_keys($meta);       foreach($page_index $page)      {        if ( strpos( strtoupper($_server['request_uri']), $page ) !== false)      {        $title        = $meta[$page]['title'];        $keywords     = $meta[$page]['keywords'];        $description = $meta[$page]['description'];        $h1           = $meta[$page]['h1'];        $h2           = $meta[$page]['h2'];        break;       }       } ?>        <!doctype html>       <html>        <head>          <meta charset="utf-8" />           <title><?php echo $title; ?></title>          <meta name="description" content="<?php echo $description; ?>">          <meta name="keywords" content="<?php echo $keywords; ?>"> 

here printed out various variables troubleshooting.

  print_r ($page_index); array ( [0] => index [1] => [2] => services [3] => blog )   print_r($meta); array ( [index] => array ( [title] => plumbers in birmingham, al | birmingham plumbers  [keywords] => plumbers in birmingham al, birmingham plumbers, plumbers birmingham al,  plumber birmingham al, plumbing birmingham al, hoover plumbing, plumbers in hoover al  [description] => plumbers in birmingham, al - servicing mountain brook, vestavia  hills, hoover, pelham, alabaster, helena, homewood , more locations. [h1] =>  best plumbers in birmingham, al [h2] => 24 hour emergency plumbing service ) [about]  => array ( [title] => company [keywords] => kwd1, kwd2, kwd3 [description] =>  company description [h1] => h1 title ) [services] => array ( [title] =>  company [keywords] => kwd1, kwd2, kwd3 [description] => company description [h1]  => h1 title ) [blog] => array ( [title] => company [keywords] => kwd1, kwd2,  kwd3 [description] => company description [h1] => h1 title ) ) 

these print nothing @ all...

print_r ($title); print_r ($keywords); print_r ($description); print_r ($h1); print_r ($h2); 

and finally....

print_r ($page); 

displays blog

so, can see code reading php file , can read array can seen meta , page index.

but breaking down on variables , page. since tested on index page , not blog page - yet returns blog.

any ideas?

lots of ways (try $_server['script_name'] or $_server['php_self'] basename():

if ( strpos( basename(strtoupper($_server['script_name'])), $page ) !== false) 

or maybe:

if ( strpos( basename(strtoupper($_server['php_self'])), $page ) !== false) 

or provide default value can try (might tweak $_server var use here well):

$page_index = array_keys($meta); $vars = $meta['index'];  foreach($page_index $page){     if ( strpos( strtoupper($_server['request_uri']), $page ) !== false) {         $vars = $meta[$page];         break;     } } $title        = $vars['title']; $keywords     = $vars['keywords']; $description  = $vars['description']; $h1           = $vars['h1']; $h2           = $vars['h2'];  //could possibly use extract($vars); instead 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -