Notice: Undefined offset: 1 in ...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • KarlBee
    Junior Member
    • Mar 2004
    • 9

    #1

    Notice: Undefined offset: 1 in ...

    Hi there,

    Could someone tell me what this actually means?

    I have my own local server running on my PC and on one include I get this error:

    Notice: Undefined offset: 1 in c:\program files\www\inc\header_inc.php on line 21

    Line 21 relates to this:

    PHP Code:
    preg_match('/href="([^"]+)"/'$line$url); 
    And this is the complete code:

    PHP Code:
    <?php
    $menu 
    = <<<MENU
        <ul>
          <li><a href="/" title="Homepage">Home</a></li>
          <li><a href="/colophon/" title="All about">Colophon</a></li>
          <li><a href="/webdesign/" title="service">Web Design</a></li>
          <li><a href="/hosting/" title="hosting packages">Hosting</a></li>
          <li><a href="/pcsupport/" title="PC Support">PC Support</a></li>
          <li><a href="/contact/" title="Contact information">Contact</a></li>
        </ul>
    MENU;

    $lines split("\n"$menu);
    foreach (
    $lines as $line) {
        
    $current false;
        
    preg_match('/href="([^"]+)"/'$line$url);
        if (
    substr($_SERVER["REQUEST_URI"], 05) == substr($url[1], 05)) {
            
    $line str_replace('<a h''<a id="active" h'$line);
            }
        echo 
    $line."\n";
    }
    ?>
    I commented out the error handling in php.ini but the error still is there.

    Any ideas?

    Thanks
    Karl
  • Buddha
    Senior Member
    • Mar 2004
    • 825

    #2
    Off the top of my head....
    PHP Code:

        
    if (substr($_SERVER["REQUEST_URI"], 05) == substr($url['1'], 05)) { 
    Just add those quotes to $url.
    Last edited by Buddha; 06-05-2004, 11:32 AM. Reason: What ya want?! A blanky blank excuse!
    "Whatcha mean I shouldn't be rude to my clients?! If you want polite then there will be a substantial fee increase." - Buddha

    Comment

    • sdjl
      Senior Member
      • Mar 2004
      • 502

      #3
      Also, you haven't assigned your preg_match code to a variable.
      I'm assuming you want to use that otherwise it's kind of pointless having it

      PHP Code:
      preg_match('/href="([^"]+)"/'$line$url); 
      Should be something like so:
      PHP Code:
      $variable preg_match('/href="([^"]+)"/'$line$url); 
      David
      -----
      Do you fear the obsolescence of the metanarrative apparatus of legitimation?

      Comment

      • keylope
        Junior Member
        • Jun 2004
        • 23

        #4
        You also be getting that if $url didn't find a match. Then there would be no offset to find.

        You might want to either first check if $url is empty and if not, then go ahead and do your comparison.

        For debugging purposes, echo the array $url and maybe you'll be able to see what is going wrong.

        Comment

        Working...