Uninitialized string offset: 0 - please help

Discussion in 'PHP' started by le007, Oct 1, 2014.

  1. #1
    Hi all,

    I'm working on this website:
    http://www.theliberal.ie/disgraceful-politicians-do-not-have-to-pay-water-charges-on-their-second-homes/

    I am trying to implement advertising. Below is the code, as you can see on line 167. I'm getting a uninitialized string offset. I have no idea what that is?

    Some of the other links work fine? For example:
    http://www.theliberal.ie/alert-first-ebola-case-confirmed-in-the-united-states/

    Please help!

    The line of code that's causing the problem is this:
    $dyn_sidebar = $GLOBALS['sbg_sidebar'][0];
    Code (markup):
    The full code for the page is this:
    <?php $post_id = null;
    $enable_full_width_post = get_post_custom_values('full_width_postthemeloy_checkbox');
    ?>
    
    <!-- begin content -->           
    <section id="contents" class="clearfix">
    <div class="row">
    
    <div class="container <?php if(of_get_option('post_layout') == '2c-r1-fixed') {}else{ echo 'two-columns-sidebar';}?><?php if(of_get_option('sidebar_center_width') ==
    
    true) {echo " center_350";}?>">
    
    
    
      <div class="sidebar_content">
            <div class="p7ehc-a <?php if($enable_full_width_post[0] == 1) {echo "grid_12";}else{echo "grid_7";}?>">
    
    
            <div id="p7EHCd_1">
                <?php $post_layout = of_get_option('post_layout'); ?>
                <?php require_once dirname(__FILE__) . '/include/single-post.php'; ?> 
            <div class="brack_space"></div>
            </div>
            </div>
            </div>
          
    <?php if($enable_full_width_post[0] == 0) { ?>      
      <div class="sidebar_center">
                <div class="p7ehc-a grid_3">
    
    
    
    
    <?php
    
    
    if(in_category('life-culture')) {
    
    ?>
    
    <!--JavaScript Tag with group ID // Tag for network 1090: Digital Reach Group_Adforce // Website: The Liberal // Page: Life & Culture // Placement: Life & Culture MPU (5190274) // created at: Oct 1, 2014 6:37:26 PM-->
    <script language="javascript">
    <!--
    if (window.adgroupid == undefined) {
        window.adgroupid = Math.round(Math.random() * 1000);
    }
    document.write('<scr'+'ipt language="javascript1.1" src="http://ad.dc2.adtech.de/addyn/3.0/1090/5190274/0/170/ADTECH;loc=100;target=_blank;grp='+window.adgroupid+';misc='+new Date().getTime()+'"></scri'+'pt>');
    //-->
    </script><noscript><a href="http://ad.dc2.adtech.de/adlink/3.0/1090/5190274/0/170/ADTECH;loc=300" target="_blank"><img src="http://ad.dc2.adtech.de/adserv/3.0/1090/5190274/0/170/ADTECH;loc=300" border="0" width="300" height="250"></a></noscript>
    <!-- End of JavaScript Tag -->
    
    
    <?php
    }
    
    
    if(in_category('opinion')) {
    
    ?>
    
    
    <!--JavaScript Tag with group ID // Tag for network 1090: Digital Reach Group_Adforce // Website: The Liberal // Page: Opinion // Placement: Opinion MPU (5249154) // created at: Oct 1, 2014 6:37:28 PM-->
    <script language="javascript">
    <!--
    if (window.adgroupid == undefined) {
        window.adgroupid = Math.round(Math.random() * 1000);
    }
    document.write('<scr'+'ipt language="javascript1.1" src="http://ad.dc2.adtech.de/addyn/3.0/1090/5249154/0/170/ADTECH;loc=100;target=_blank;grp='+window.adgroupid+';misc='+new Date().getTime()+'"></scri'+'pt>');
    //-->
    </script><noscript><a href="http://ad.dc2.adtech.de/adlink/3.0/1090/5249154/0/170/ADTECH;loc=300" target="_blank"><img src="http://ad.dc2.adtech.de/adserv/3.0/1090/5249154/0/170/ADTECH;loc=300" border="0" width="300" height="250"></a></noscript>
    <!-- End of JavaScript Tag -->
    
    
    
    
    
    <?php
    }
    
    if(in_category('politics')) {
    
    ?>
    
    
    <!--JavaScript Tag with group ID // Tag for network 1090: Digital Reach Group_Adforce // Website: The Liberal // Page: Politics // Placement: Politics MPU (5190276) // created at: Oct 1, 2014 6:37:26 PM-->
    <script language="javascript">
    <!--
    if (window.adgroupid == undefined) {
        window.adgroupid = Math.round(Math.random() * 1000);
    }
    document.write('<scr'+'ipt language="javascript1.1" src="http://ad.dc2.adtech.de/addyn/3.0/1090/5190276/0/170/ADTECH;loc=100;target=_blank;grp='+window.adgroupid+';misc='+new Date().getTime()+'"></scri'+'pt>');
    //-->
    </script><noscript><a href="http://ad.dc2.adtech.de/adlink/3.0/1090/5190276/0/170/ADTECH;loc=300" target="_blank"><img src="http://ad.dc2.adtech.de/adserv/3.0/1090/5190276/0/170/ADTECH;loc=300" border="0" width="300" height="250"></a></noscript>
    <!-- End of JavaScript Tag -->
    
    <?php
    }
    
    if(in_category('irish-news')) {
    
    ?>
    
    
    <!--JavaScript Tag with group ID // Tag for network 1090: Digital Reach Group_Adforce // Website: The Liberal // Page: Irish News // Placement: Irish News MPU (5190270) // created at: Oct 1, 2014 6:37:27 PM-->
    <script language="javascript">
    <!--
    if (window.adgroupid == undefined) {
        window.adgroupid = Math.round(Math.random() * 1000);
    }
    document.write('<scr'+'ipt language="javascript1.1" src="http://ad.dc2.adtech.de/addyn/3.0/1090/5190270/0/170/ADTECH;loc=100;target=_blank;grp='+window.adgroupid+';misc='+new Date().getTime()+'"></scri'+'pt>');
    //-->
    </script><noscript><a href="http://ad.dc2.adtech.de/adlink/3.0/1090/5190270/0/170/ADTECH;loc=300" target="_blank"><img src="http://ad.dc2.adtech.de/adserv/3.0/1090/5190270/0/170/ADTECH;loc=300" border="0" width="300" height="250"></a></noscript>
    <!-- End of JavaScript Tag -->
    
    <?php
    }
    
    
    if(in_category('world-news')) {
    
    ?>
    
    
    <!--JavaScript Tag with group ID // Tag for network 1090: Digital Reach Group_Adforce // Website: The Liberal // Page: World News // Placement: World News MPU (5255129) // created at: Oct 1, 2014 6:37:28 PM-->
    <script language="javascript">
    <!--
    if (window.adgroupid == undefined) {
        window.adgroupid = Math.round(Math.random() * 1000);
    }
    document.write('<scr'+'ipt language="javascript1.1" src="http://ad.dc2.adtech.de/addyn/3.0/1090/5255129/0/170/ADTECH;loc=100;target=_blank;grp='+window.adgroupid+';misc='+new Date().getTime()+'"></scri'+'pt>');
    //-->
    </script><noscript><a href="http://ad.dc2.adtech.de/adlink/3.0/1090/5255129/0/170/ADTECH;loc=300" target="_blank"><img src="http://ad.dc2.adtech.de/adserv/3.0/1090/5255129/0/170/ADTECH;loc=300" border="0" width="300" height="250"></a></noscript>
    <!-- End of JavaScript Tag -->
    
    
    <?php
    }
    
    
    if(in_category('business')) {
    
    ?>
    
    
    <!--JavaScript Tag with group ID // Tag for network 1090: Digital Reach Group_Adforce // Website: The Liberal // Page: Business // Placement: Business MPU (5190268) // created at: Oct 1, 2014 6:37:26 PM-->
    <script language="javascript">
    <!--
    if (window.adgroupid == undefined) {
        window.adgroupid = Math.round(Math.random() * 1000);
    }
    document.write('<scr'+'ipt language="javascript1.1" src="http://ad.dc2.adtech.de/addyn/3.0/1090/5190268/0/170/ADTECH;loc=100;target=_blank;grp='+window.adgroupid+';misc='+new Date().getTime()+'"></scri'+'pt>');
    //-->
    </script><noscript><a href="http://ad.dc2.adtech.de/adlink/3.0/1090/5190268/0/170/ADTECH;loc=300" target="_blank"><img src="http://ad.dc2.adtech.de/adserv/3.0/1090/5190268/0/170/ADTECH;loc=300" border="0" width="300" height="250"></a></noscript>
    <!-- End of JavaScript Tag -->
    
    <?php
    }
    ?>
    
    
    
    
    
                <div id="p7EHCd_2"> 
    <?php
                    $dyn_sidebar = $GLOBALS['sbg_sidebar'][0];
                   
                    $po_sidebar = of_get_option('po_sidebar','');   
                    if(!empty($po_sidebar)) {
                        $dyn_sidebar = $po_sidebar;
                    };               
                   
                    foreach ( $GLOBALS['wp_registered_sidebars'] as $sidebar ) {
                        if($sidebar['name'] == $dyn_sidebar)
                              {
                                 $dyn_sidebar = $sidebar['id'];
                            }
                    }
                    if($dyn_sidebar) {
                        if (is_active_sidebar($dyn_sidebar)) : dynamic_sidebar($dyn_sidebar);
                        endif;   
                    } else{
                        if (is_active_sidebar('center-sidebar')) : dynamic_sidebar('center-sidebar');
                        endif;
                    }                   
    ?>
    <div class="brack_space"></div>
    </div>
                </div>
           </div>
           <?php }?>
          
            <?php
            if($enable_full_width_post[0] == 0) {
            if(of_get_option('post_layout') == '2c-r1-fixed') {  ?>          
             <div class="sidebar_last">
                <div class="p7ehc-a grid_2">
                <div id="p7EHCd_3">
                <div class="sidebar_last_space"></div>
                    <?php
                    if (is_active_sidebar('last-sidebar')) : dynamic_sidebar('last-sidebar');
                    endif;
                    ?>
                   <div class="brack_space"></div>
                   </div>
                </div>
            </div>
             <?php }} ?>       
        </div>
    </div>
    </section>
    <!-- end content -->
    <?php
    
    
    if(is_category('life-culture') || in_category('life-culture')) {
    
    ?>
    
    <!--JavaScript Tag with group ID // Tag for network 1090: Digital Reach Group_Adforce // Website: The Liberal // Page: Life & Culture // Placement: Life & Culture Skin (5190273) // created at: Oct 1, 2014 6:37:26 PM-->
    <script language="javascript">
    <!--
    if (window.adgroupid == undefined) {
        window.adgroupid = Math.round(Math.random() * 1000);
    }
    document.write('<scr'+'ipt language="javascript1.1" src="http://ad.dc2.adtech.de/addyn/3.0/1090/5190273/0/16/ADTECH;loc=100;target=_blank;grp='+window.adgroupid+';misc='+new Date().getTime()+'"></scri'+'pt>');
    //-->
    </script><noscript><a href="http://ad.dc2.adtech.de/adlink/3.0/1090/5190273/0/16/ADTECH;loc=300" target="_blank"><img src="http://ad.dc2.adtech.de/adserv/3.0/1090/5190273/0/16/ADTECH;loc=300" border="0" width="1" height="1"></a></noscript>
    <!-- End of JavaScript Tag -->
    
    
    <?php
    }
    
    
    if(is_category('opinion') || in_category('opinion')) {
    
    ?>
    
    
    <!--JavaScript Tag with group ID // Tag for network 1090: Digital Reach Group_Adforce // Website: The Liberal // Page: Opinion // Placement: Opinion Skin (5255122) // created at: Oct 1, 2014 6:37:28 PM-->
    <script language="javascript">
    <!--
    if (window.adgroupid == undefined) {
        window.adgroupid = Math.round(Math.random() * 1000);
    }
    document.write('<scr'+'ipt language="javascript1.1" src="http://ad.dc2.adtech.de/addyn/3.0/1090/5255122/0/16/ADTECH;loc=100;target=_blank;grp='+window.adgroupid+';misc='+new Date().getTime()+'"></scri'+'pt>');
    //-->
    </script><noscript><a href="http://ad.dc2.adtech.de/adlink/3.0/1090/5255122/0/16/ADTECH;loc=300" target="_blank"><img src="http://ad.dc2.adtech.de/adserv/3.0/1090/5255122/0/16/ADTECH;loc=300" border="0" width="1" height="1"></a></noscript>
    <!-- End of JavaScript Tag -->
    
    
    
    
    
    <?php
    }
    
    if(is_category('politics') || in_category('politics')) {
    
    ?>
    
    
    <!--JavaScript Tag with group ID // Tag for network 1090: Digital Reach Group_Adforce // Website: The Liberal // Page: Politics // Placement: Politics Skin (5190277) // created at: Oct 1, 2014 6:37:27 PM-->
    <script language="javascript">
    <!--
    if (window.adgroupid == undefined) {
        window.adgroupid = Math.round(Math.random() * 1000);
    }
    document.write('<scr'+'ipt language="javascript1.1" src="http://ad.dc2.adtech.de/addyn/3.0/1090/5190277/0/16/ADTECH;loc=100;target=_blank;grp='+window.adgroupid+';misc='+new Date().getTime()+'"></scri'+'pt>');
    //-->
    </script><noscript><a href="http://ad.dc2.adtech.de/adlink/3.0/1090/5190277/0/16/ADTECH;loc=300" target="_blank"><img src="http://ad.dc2.adtech.de/adserv/3.0/1090/5190277/0/16/ADTECH;loc=300" border="0" width="1" height="1"></a></noscript>
    <!-- End of JavaScript Tag -->
    
    
    
    <?php
    }
    
    if(is_category('irish-news') || in_category('irish-news')) {
    
    ?>
    
    
    <!--JavaScript Tag with group ID // Tag for network 1090: Digital Reach Group_Adforce // Website: The Liberal // Page: Irish News // Placement: Irish News Skin (5190271) // created at: Oct 1, 2014 6:37:27 PM-->
    <script language="javascript">
    <!--
    if (window.adgroupid == undefined) {
        window.adgroupid = Math.round(Math.random() * 1000);
    }
    document.write('<scr'+'ipt language="javascript1.1" src="http://ad.dc2.adtech.de/addyn/3.0/1090/5190271/0/16/ADTECH;loc=100;target=_blank;grp='+window.adgroupid+';misc='+new Date().getTime()+'"></scri'+'pt>');
    //-->
    </script><noscript><a href="http://ad.dc2.adtech.de/adlink/3.0/1090/5190271/0/16/ADTECH;loc=300" target="_blank"><img src="http://ad.dc2.adtech.de/adserv/3.0/1090/5190271/0/16/ADTECH;loc=300" border="0" width="1" height="1"></a></noscript>
    <!-- End of JavaScript Tag -->
    
    
    <?php
    }
    
    if(is_category('world-news') || in_category('world-news')) {
    
    ?>
    
    
    <!--JavaScript Tag with group ID // Tag for network 1090: Digital Reach Group_Adforce // Website: The Liberal // Page: World News // Placement: World News Skin (5255130) // created at: Oct 1, 2014 6:37:28 PM-->
    <script language="javascript">
    <!--
    if (window.adgroupid == undefined) {
        window.adgroupid = Math.round(Math.random() * 1000);
    }
    document.write('<scr'+'ipt language="javascript1.1" src="http://ad.dc2.adtech.de/addyn/3.0/1090/5255130/0/16/ADTECH;loc=100;target=_blank;grp='+window.adgroupid+';misc='+new Date().getTime()+'"></scri'+'pt>');
    //-->
    </script><noscript><a href="http://ad.dc2.adtech.de/adlink/3.0/1090/5255130/0/16/ADTECH;loc=300" target="_blank"><img src="http://ad.dc2.adtech.de/adserv/3.0/1090/5255130/0/16/ADTECH;loc=300" border="0" width="1" height="1"></a></noscript>
    <!-- End of JavaScript Tag -->
    
    
    <?php
    }
    
    if(is_category('business') || in_category('business')) {
    
    ?>
    
    
    <!--JavaScript Tag with group ID // Tag for network 1090: Digital Reach Group_Adforce // Website: The Liberal // Page: Business // Placement: Business Skin (5190266) // created at: Oct 1, 2014 6:37:26 PM-->
    <script language="javascript">
    <!--
    if (window.adgroupid == undefined) {
        window.adgroupid = Math.round(Math.random() * 1000);
    }
    document.write('<scr'+'ipt language="javascript1.1" src="http://ad.dc2.adtech.de/addyn/3.0/1090/5190266/0/16/ADTECH;loc=100;target=_blank;grp='+window.adgroupid+';misc='+new Date().getTime()+'"></scri'+'pt>');
    //-->
    </script><noscript><a href="http://ad.dc2.adtech.de/adlink/3.0/1090/5190266/0/16/ADTECH;loc=300" target="_blank"><img src="http://ad.dc2.adtech.de/adserv/3.0/1090/5190266/0/16/ADTECH;loc=300" border="0" width="1" height="1"></a></noscript>
    <!-- End of JavaScript Tag -->
    
    
    <?php
    }
    ?>
    
    Code (markup):
     
    Solved! View solution.
    le007, Oct 1, 2014 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    do a print_r($GLOBALS); or print_r($GLOBALS['sbg_sidebar']); before the offending line, and see if there's an actual array in there. If it's not, then you've found your error.
    Using GLOBALS (of any kind, maybe except for inside functions), and not checking to see if a value / variable / array exist before using it is bad practice, and will return errors and/or warnings.
     
    PoPSiCLe, Oct 2, 2014 IP
  3. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #3
    Hi, thanks for your reply. I'm a css guy, I've no idea of php, im just taking over from someone. Could you please give me code or an alternative code to what I need?

    Thank you!
     
    le007, Oct 2, 2014 IP
  4. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #4
    Since I don't know what you $GLOBALS contain, no, I can't. Can you do the print_r($GLOBALS['sbg_sidebar']); and post what it outputs? Preferably both on a page that works, and one that doesn't.
     
    PoPSiCLe, Oct 2, 2014 IP
  5. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #5
    No problem. I can't for 3 hrs but will then immediately. Thank you for you help
     
    le007, Oct 2, 2014 IP
  6. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #6
    Sorry for delay:
    Result is as follows: Array ( [0] => 0 )

    What does this mean please?
     
    le007, Oct 2, 2014 IP
  7. #7
    That means that you have an array with a key 0 with value 0.
    And I'm also assuming that you DON'T have an array on the other page (the one with the error). Which returns the error you're seeing - (it can't find the array key 0, hence it can't process the request).
    You can fix this by doing something like this:
    instead of
    
    $dyn_sidebar = $GLOBALS['sbg_sidebar'][0];
    
    Code (markup):
    do something like this:
    
    $dyn_sidebar = is_array($GLOBALS['sbg_sidebar']) ? $GLOBALS['sbg_sidebar'][0] : '';
    
    Code (markup):
    That should make the $dyn_sidebar an empty variable if the sbg_sidebar-array isn't actually an array (and if it is an array, it should resolve without trouble)
     
    PoPSiCLe, Oct 2, 2014 IP