Undefined offset in PHP Class - wikipedia
<p>I am new to PHP - I keep getting an undefined offset in my php class.</p>

<p>Can anyone help please - my code is below. Current error is on line 28 but there may be more.</p>

<p>The Error Displayed is:</p>

<blockquote>
  <p>Notice: Undefined offset: 0 in
  C:\xampp\htdocs\mysite\wikipedia.class.php on line 28</p>
</blockquote>

<p>This class enables me to parse wikipedia content and display it in php - any ideas what the undefined offset may be.</p>

<pre><code>&lt;?PHP
class wikipedia
{
public function __construct($wiki)
    {
    $this-&gt;wiki = $wiki;
    }
public function __destruct()
    {
    unset($this-&gt;wiki);
    }
public function get_page($name, $header = false)
    {
    $file = file_get_contents($this-&gt;wiki.'/wiki/'.$name);
    $file = str_replace('href="/', 'href="'.$this-&gt;wiki.'/', $file);
    //$file = str_replace('href="#', 'href="'.$this-&gt;wiki.'/wiki/'.$name.'#',      $file);
    preg_match_all('#&lt;!-- start content --&gt;(.*?)&lt;!-- end content --&gt;#es',  $file, $ar);
    unset($file);
    IF(is_array($ar[1]))
        {
        IF($header == false)
            {
            return $ar[1][0];
            }
        else
            {
            return '&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl" dir="ltr"&gt;&lt;head&gt;&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
            &lt;link rel="stylesheet" type="text/css" href="'.$this-&gt;wiki.'/skins-1.5/monobook/main.css" /&gt;&lt;/head&gt;&lt;body&gt;'.$ar[1][0];
            }
        }
    else
        {
        return false;
        }
    }
public function edit_page($name, $header = false)
    {
    $file = file_get_contents($this-&gt;wiki.'/w/index.php?  title='.$name.'&amp;action=edit');
    preg_match_all('#&lt;textarea (.*?)ols=\'80\' &gt;(.*?)&lt;/textarea&gt;#es', $file,  $ar);
    unset($file);
    IF(is_array($ar[2]))
        {
        ob_start();
        IF($header != false)
            {
            echo '&lt;html xmlns="http://www.w3.org/1999/xhtml"  xml:lang="pl" lang="pl" dir="ltr"&gt;&lt;head&gt;&lt;meta http-equiv="Content-Type" content="text/html;  charset=utf-8" /&gt;
            &lt;link rel="stylesheet" type="text/css" href="'.$this- &gt;wiki.'/skins-1.5/monobook/main.css" /&gt;&lt;/head&gt;&lt;body&gt;';
            }

        $xname = 'wpTextbox1';
        echo '&lt;Form action="'.$this-&gt;wiki.'/w/index.php? title='.$name.'&amp;amp;action=submit" METHOD="POST" enctype="multipart/form-data" name="rk"  id="editform"&gt;&lt;center&gt;
        &lt;script language="JavaScript"&gt;
            function emoticon('.$xname.') {
            '.$xname.' = \'\' + '.$xname.' + \'\';
            if (document.rk.'.$xname.'.create'.$xname.'Range &amp;&amp;  document.rk.'.$xname.'.caretPos) {
            var caretPos = document.rk.'.$xname.'.caretPos;
            caretPos.'.$xname.' =  caretPos.'.$xname.'.charAt(caretPos.'.$xname.'.length - 1) == \' \' ? '.$xname.' + \' \' :  '.$xname.';
            document.rk.'.$xname.'.focus();
            } else {
            document.rk.'.$xname.'.value  += '.$xname.';
            document.rk.'.$xname.'.focus();
            }
            }
            &lt;/script&gt;';

            echo '&lt;center&gt;&lt;textarea cols="75" rows="30" name="'.$xname.'"&gt;'.$ar[2][0].'&lt;/textarea&gt;&lt;BR&gt;
            &lt;input type="button" value="Link to a wiki page" onClick="javascript:emoticon(\'[[wiki_page]]\')"&gt;
            &lt;input type="button" value="Link" onClick="javascript:emoticon(\'[http://your_url.pl Page Title]\')"&gt;
            &lt;input type="button" value="Graphic" onClick="javascript:emoticon(\'[[Grafika:filename]]\')"&gt;
            &lt;input type="button" value="H1 - Big Title" onClick="javascript:emoticon(\'= Title =\')"&gt;
            &lt;input type="button" value="H2 - Medium Title" onClick="javascript:emoticon(\'== Title ==\')"&gt;
            &lt;input type="button" value="H3 - Small Title" onClick="javascript:emoticon(\'=== Title ===\')"&gt;
            &lt;input type="button" value="LI - lists" onClick="javascript:emoticon(\'* Text here\')"&gt;
            &lt;input type="button" value="LI - numeric lists" onClick="javascript:emoticon(\'# Text here\')"&gt;
            &lt;input type="button" value="Definition" onClick="javascript:emoticon(\'; Definition name : Description\')"&gt;
            &lt;input type="button" value="HR - line" onClick="javascript:emoticon(\'----\')"&gt;&lt;BR&gt;&lt;BR&gt;';

        echo '&lt;BR&gt;&lt;input tabindex=\'5\' id=\'wpSave\' type=\'submit\' value="Save" name="wpSave" accesskey="s"&gt;
        &lt;input tabindex=\'6\' id=\'wpPreview\' type=\'submit\'  value="Preview" name="wpPreview" accesskey="p"&gt;
        &lt;input tabindex=\'7\' id=\'wpDiff\' type=\'submit\' value="Preview Changes" name="wpDiff" accesskey="v"&gt;&lt;/center&gt;&lt;/form&gt;';
        $wynik = ob_get_contents();
        ob_end_clean();
        return $wynik;
        }
    else
        {
        return false;
        }
    }
    }
?&gt;
</code></pre>
