Undefined variable

Discussion in 'PHP' started by bandittoss, Oct 20, 2010.

  1. #1
    Please help to resolve this problem. Im not programmer but im really need help to fix this problem.

    if( TP_MASONRY )
    {
    $this->item->text = JFilterOutput::ampReplace($this->item->text);
    preg_match_all("/<img[^>]*>/Ui", $this->item->text, $txtimg);
    if (!empty($txtimg[0])) {
    foreach ($txtimg[0] as $txtimgel) {
    $this->item->text = str_replace($txtimgel,"",$this->item->text);
    if ( $n == 0 )
    {
    preg_match_all("#src=\"([\:\-\/\_A-Za-z0-9\.]+)\"#",$txtimgel,$txtimgelsr);
    $this->item->img = ( !empty( $txtimgelsr[1][0] ) ) ? $txtimgelsr[1][0] : null;
    }

    }
    }
    }

    Undefines variable: if ( $n == 0 )

    Thanks in advance
     
    bandittoss, Oct 20, 2010 IP
  2. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #2
    Change it to:

    if (isset($n) && $n == 0 )
     
    ThePHPMaster, Oct 20, 2010 IP
  3. bandittoss

    bandittoss Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    nope, lose image on front page if use isset or change $n :(

    this script is related for showing images on the front page
     
    bandittoss, Oct 20, 2010 IP
  4. silviuks

    silviuks Peon

    Messages:
    43
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    are you initializing $n somewhere in your code?

    did you tried: if($n && $n == 0) ... ?
     
    silviuks, Oct 21, 2010 IP
  5. djarotstudio

    djarotstudio Member

    Messages:
    200
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    33
    #5
    Paste the error message please. Error message is always our square one to go further.
    With no error message, all advices you have would be nothing more then crawling in the dark.
     
    djarotstudio, Oct 21, 2010 IP