Website problems (Use of undefined constant str_pad_left)

Discussion in 'Web Design and Development' started by Brendon Bauer, Jul 26, 2008.

  1. Brendon Bauer macrumors 6502

    Joined:
    May 14, 2007
    Location:
    Good 'ol USofA
    #1
    The index.php file of my website is giving me an error right above where I have a php include. The error is this:

    Notice: Use of undefined constant str_pad_left - assumed 'str_pad_left' in /hsphere/local/home/trienell/summitnorthwest.org/includes/thisweek.php on line 13 Notice: Use of undefined constant str_pad_left - assumed 'str_pad_left' in /hsphere/local/home/trienell/summitnorthwest.org/includes/thisweek.php on line 20

    The include is for a file in /includes/thisweek.php. The code for thisweek.php is:

    Code:
    <?php 
    $paras = array( 
      '30' => 'Date: Saturday, July 26<br />Speaker: Ron Hessel<br />Sermon Title/Topic: The Child of Faith<br />Sermon Series: Father Abraham: Friend of God<br />Music Team: Bruce Christensen, Gayle Dohrman, Terry & Keriana Forrester, Skip Meyer, Kelly Sailas, Cher Leiske, Kevin Smith, Sam Smith, and Mike Christensen.',
      '31' => 'Date: Saturday, August 2<br />Speaker: Ron Hessel<br />Sermon Title/Topic: The Testing of Faith<br />Sermon Series: Father Abraham: Friend of God<br />Music Team: Kelly Armstrong, Brad & Karen Drury, Fred & Mindy Weber, Lindsay Armstrong, Sydney Drury, Bruce Christensen, Kevin Smith, Sam Smith, and Liz Coulter.',
      '32' => 'Date: Saturday, August 9<br />Speaker: Ron Hessel<br />Sermon Title/Topic: How to Know if you are Living<br />Sermon Series: Abundant Life Bootcamp, Part II<br />Music Team: Geoff Heald, Tina Bauer, Mike & Tawnya Breakie, Carrie Graves, Karalee Rhuman, Kelly Armstrong, Brad Billington, Kevin Smith, and Ron Tobin.',
      '33' => 'Date: Saturday, August 16<br />Speaker: Ron Hessel<br />Sermon Title/Topic: Actually Living<br />Sermon Series: Abundant Life Bootcamp, Part II<br />Music Team: Brad & Nancy Billington, Mike Christensen, Jeremy Marinos, Sherliyn Jones, Kevin Smith, and Bryan and Kim Anderson.',
      '34' => 'Date: Saturday, August 23<br />Speaker: Ron Hessel<br />Sermon Title/Topic: Peaceful Evangelism<br />Sermon Series: Abundant Life Bootcamp, Part II<br />Music Team: Bruce Christensen, Gayle Dohrman, Terry & Keriana Forrester, Skip Meyer, Kelly Sailas, Cher Leiske, Kevin Smith, Sam Smith, and Mike Christensen.');
     
    $today = date("W");
    // The number below represents which day of the week begins a new week. By default a new week begins on Monday, but we wanted the script to update Saturday night at midnight (on Sunday) instead of Sunday night at midnight (on Monday) we use a 0. 0 = Sunday, 6 = Saturday. Because we put in 0, the script will update as soon as 12:01 Sunday arrives. If we want the script to update on Wednesday at midnight, we'd use a 4 instead. Well not 100% true... It actually just always bumps Sunday forward to the next week, so it would take more modifying than that.
    if (date("w") == 0) {
    	$myday = $today+1;
    	$today = str_pad($myday,2,'0',str_pad_left);
    }
    $nextweek = strtotime("+1 week");
    $nextweek = date('W',$nextweek);
    // Same goes for the number below as well.
    if (date("w") == 0) {
    	$mydaynextweek = $nextweek+1;
    	$nextweek = str_pad($mydaynextweek,2,'0',str_pad_left);
    }
    foreach ($paras as $key => $para) {
      if ($today == $key) { 
    	print $para; 
      }
    }
    echo "</p><h3 class=\"title\">Next week at Summit Northwest Ministries</h3><p>";
    foreach ($paras as $key => $para) { 
      if ($nextweek == $key) { 
    	print $para; 
      }
    }
    ?>
    That script is used to display what's happening this week and next week for church. It updates every weekend, and what's displayed corresponds to the week # of the year. I haven't changed anything for a long time (more than a year ago?) other than adding more weeks as we go along, but for some reason it just now started showing up in the last day or two...

    Any ideas?
     
  2. thejadedmonkey macrumors 604

    thejadedmonkey

    Joined:
    May 28, 2005
    Location:
    Pa
    #2
    That's an error, but not fatal. It's probably a config change with PHP, perhaps if PHP was just updated.

    Try turning all instances of str_pad_left to 'str_pad_left' or "str_pad_left" (it's been too long since I looked at PHP, I don't remember which might fix it). Right now str_pad_left isn't being declared as a variable i think because there's no quotes around it.

    But I could be completely wrong, as I need sleep.
     
  3. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #3
    Constants should be typed in all uppercase:
    Code:
    $today = str_pad($myday,2,'0',[B]STR_PAD_LEFT[/B]);
     
  4. Brendon Bauer thread starter macrumors 6502

    Joined:
    May 14, 2007
    Location:
    Good 'ol USofA
    #4
    Wow, pure genius. The uppercase suggestion worked. But thanks for the quick reply monkey :D. And thanks angelwatt for coming to the rescue once again.
     

Share This Page