SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    philmont
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how do I get rid of: notice error

    Just curious as to why I'm getting an error on this page....
    I've never had one before but now it started up and I cant seem to get rid of this error::

    Notice: Undefined offset: 3 in **DIR**webroot\links.php on line 30


    <?php

    $display = 10;

    if ( $handle = opendir("./Discussion/links/") )
    {
    while ( ( $file = readdir( $handle ) ) !== false )
    {
    if ( $file != "." && $file != ".." )
    {
    $news_array[] = $file;
    }
    }
    closedir( $handle );
    }

    array_multisort( $news_array, SORT_NUMERIC, SORT_DESC );
    array_splice( $news_array, $display );

    $num_news = ( count( $news_array ) );

    foreach ( $news_array as $val )
    {
    $news_file = file("./discussion/links/$val");


    $date = $news_file[0];
    $author = $news_file[1];
    $texts = $news_file[2];
    $links = $news_file[3];
    $link = "$links";
    $text = stripslashes($texts);
    $needle = "http://";
    $check = strpos($link, $needle);

    if($check === false)
    {
    //if "http://" is not present in $link, prepend it yourself
    $correctLink = "http://" . $link;
    }
    else
    {
    //the given link was okay
    $correctLink = $link;
    }

    echo "<font color='white'><b>".$date."</b><br>";
    echo '<small>Written by: '.$author.'</small><br>';
    print "<a href=\"" . $correctLink . "\"><body vlink='yellow'>" . $correctLink . "</a><br>";
    print "&nbsp;&nbsp - ";
    echo $text;
    echo ' </font><body vlink="#BABABA"><a href="#beginning"><font size="-2" color="#BABABA">Top</font></a><br><br>';
    }

    ?>

  2. #2
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's a NOTICE not strictly an error, caused by:
    $links = $news_file[3];
    It means that there is no 4th element in the $news_file array.

    Yoiu can either fix it (preffered) or hide the notice by putting error_reporting(0); at the top of your script

  3. #3
    SitePoint Guru defiance's Avatar
    Join Date
    Oct 2004
    Location
    United states
    Posts
    663
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if($check === false)

    you have 3 =

    change it to only 2

    -----------------------------------
    print "&nbsp;&nbsp - ";

    yuo forgot semilcolon on the second nbsp

    and try echoing out

    print_r($news_file);

    and see if you have 4th element coz you are trying to echo
    $links = $news_file[3];

  4. #4
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if($check === false)
    you have 3 =
    change it to only 2
    3 ='s are ok and quite correct in this case

  5. #5
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    philmont
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks- I just went back in and noticed that there wasnt anything listed for that link.

    how would I go about fixing this if nothing is placed within that particular location?

    I would guess using the trim function?
    $link= trim($link);
    if(!empty($link))
    {
    echo $link;

    }

  6. #6
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe:
    PHP Code:
    $links = isset($news_file[3]) ? $news_file[3] ? ''
    Further down you'll want:
    if($check === false && !empty($link))

  7. #7
    SitePoint Guru defiance's Avatar
    Join Date
    Oct 2004
    Location
    United states
    Posts
    663
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by markl999
    3 ='s are ok and quite correct in this case
    opps

    sorry abt that.
    thanks mark.

    3 ='s is used to check for logic value?

  8. #8
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    == checks if the values match.
    === checks the value and the type match (int, string, bool etc..).

  9. #9
    SitePoint Guru defiance's Avatar
    Join Date
    Oct 2004
    Location
    United states
    Posts
    663
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by markl999
    == checks if the values match.
    === checks the value and the type match (int, string, bool etc..).
    ermm
    ic
    thanks

  10. #10
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    philmont
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is this how I put it in?
    <?php

    $display = 10;

    if ( $handle = opendir("./Discussion/links/") )
    {
    while ( ( $file = readdir( $handle ) ) !== false )
    {
    if ( $file != "." && $file != ".." )
    {
    $news_array[] = $file;
    }
    }
    closedir( $handle );
    }

    array_multisort( $news_array, SORT_NUMERIC, SORT_DESC );
    array_splice( $news_array, $display );

    $num_news = ( count( $news_array ) );

    foreach ( $news_array as $val )
    {
    $news_file = file("./discussion/links/$val");


    $date = $news_file[0];
    $author = $news_file[1];
    $texts = $news_file[2];
    $links = isset($news_file[3]) ? $news_file[3] ? '';
    $text = stripslashes($texts);
    $link = "$links";
    $needle = "http://";
    $check = strpos($link, $needle);

    if($check === false && !empty($link))
    {
    //if "http://" is not present in $link, prepend it yourself
    $correctLink = "http://" . $link;
    }
    else
    {
    //the given link was okay
    $correctLink = $link;
    }

    echo "<font color='white'><b>".$date."</b><br>";
    echo '<small>Written by: '.$author.'</small><br>';
    print "<a href=\"" . $correctLink . "\"><body vlink='yellow'>" . $correctLink . "</a><br>";
    print "&nbsp;&nbsp; - ";
    echo $text;
    echo ' </font><body vlink="#BABABA"><a href="#beginning"><font size="-2" color="#BABABA">Top</font></a><br><br>';
    }

    ?>


    when I do this, I get::
    Parse error: parse error, unexpected ';' in **DIR**\webroot\links.php on line 30

  11. #11
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, my typo, i meant:
    $links = isset($news_file[3]) ? $news_file[3] : '';

  12. #12
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    philmont
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that did it- thanks, I appreciate it


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •