title: Creating an object from a class in Codeigniter
body: <p>The following codes are from <a href="http://d.hatena.ne.jp/dix3/20081002/1222899116" rel="nofollow noreferrer">http://d.hatena.ne.jp/dix3/20081002/1222899116</a> and codes are working well.</p>
  
  <p>This is an example of using <a href="http://snoopy.sourceforge.net/" rel="nofollow noreferrer">snoopy</a> in codeigniter.</p>
  
  <p>Q1. Am I correct to say that I can't use,</p>
  
  <pre><code>$this -&gt; load -&gt; library('snoopy')
  </code></pre>
  
  <p>since Snoopy.php does not create an object. And the example below is the way to do it?
  If so, can you explain/direct me an tutorial or explanation of how to do it in details?</p>
  
  <pre><code>if ( ! class_exists('Snoopy'))
      {
          require_once(APPPATH.'libraries/Snoopy'.EXT);
      }
  </code></pre>
  
  <p>Q2. Why do the author use </p>
  
  <pre><code>$to_specialchars=true
  </code></pre>
  
  <p>Is it needed for this?</p>
  
  <p>Q3. Could you explain APPPATH and EXT.</p>
  
  <pre><code>APPPATH.'libraries/Snoopy'.EXT
  </code></pre>
  
  <p>I checked it in php.net but I could not find it. EXT must be extension, but can I use anywhere?</p>
  
  <p>Thanks in advance.</p>
  
  <p>I have a snoopy in application/library/Snoopy.php</p>
  
  <p>I have application/library/Snoopy.php</p>
  
  <pre><code>&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  
  class Scraping{
      var $c; 
      function Scraping(){
          if ( ! class_exists('Snoopy'))
          {
              require_once(APPPATH.'libraries/Snoopy'.EXT);
          }
          $this -&gt; c = new Snoopy();
      }
  
      function getWebHtml($url="",$to_specialchars=true){
          $this -&gt;c -&gt; fetch( $url );
          $str = mb_convert_encoding( (string) $this -&gt; c -&gt; results,"UTF-8","auto");
          return ($to_specialchars) ? htmlspecialchars($str , ENT_QUOTES , "UTF-8" ) : $str ;
      }
  
     function getWebText($url="",$to_specialchars=true){
          $this -&gt; c -&gt; fetchtext( $url );
          $str = mb_convert_encoding( (string) $this -&gt; c -&gt; results,"UTF-8","auto");
          return ($to_specialchars) ? htmlspecialchars($str , ENT_QUOTES , "UTF-8" ) : $str ;
      }
  
      function getWebLinks($url=""){
          $this -&gt; c -&gt; fetchlinks( $url );
          return (array) $this-&gt; c -&gt; results ;
      }
  
      function getWebLinksText($url="",$delimiter="&lt;br&gt;"){
          $arr = $this-&gt; getWebLinks($url) ;
          $ret ="";
          foreach($arr as $k =&gt; $v){
              $ret .= $v . $delimiter ;
          }
          return $ret;
      }
  
  } //endofclass
  
  /* End of file Scraping.php */
  /* Location: ./application/libraries/Scraping.php */
   ?&gt;
  </code></pre>
  
  <p>I have a controller application/controller/mytasklist.php</p>
  
  <pre><code>&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  
  class Mytasklist extends Controller {
  
  function Mytasklist()
  {
    parent :: Controller(); 
  
    $this -&gt; load -&gt; helper( 'url' ); 
  
  } 
  
      function index()
      {
        $data = "";
  
        $this -&gt; _SetTpl( $data );
      } 
   function _SetTpl( $data )
  { 
  
  
    $this -&gt; load -&gt; library("scraping");
    $data["scraping"]["text"] = $this-&gt; scraping -&gt; getWebText("http://www.example.com/");
    $data["scraping"]["html"] = $this-&gt; scraping -&gt; getWebHtml("http://www.example.com/");
    $data["scraping"]["link"] = $this-&gt; scraping -&gt; getWebLinksText("http://www.example.com/","\n");
  
    $tpl["page_title"] = "Welcome";
  
    $tpl["main_content"] = $this -&gt; load -&gt; view( 'tasklist_view', $data , true ); 
  
    $this -&gt; load -&gt; view( 'base_view', $tpl );
  } 
  
  
  }
  </code></pre>
  
  <p>And I have a view, application/view/base_view.php</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja"&gt;
  &lt;head&gt;
      &lt;meta http-equiv="content-type" content="text/html; charset=utf-8"/&gt;
      &lt;meta name="keywords" content="keyword here" /&gt;
      &lt;meta name="description" content="description here" /&gt;
      &lt;title&gt;&lt;?php if(isset($page_title)){echo $page_title ;}?&gt;&lt;/title&gt;
      &lt;?php if(isset($xajax_js)){echo $xajax_js ;}?&gt;
      &lt;link href="http://127.0.0.1/ci_day4/css/mystyle.css" rel="stylesheet" type="text/css"/&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;div id="container"&gt;
  
  
      &lt;div id="rightblock"&gt;
  
          &lt;div id="content"&gt;
  
              &lt;?=$main_content?&gt;
  
          &lt;/div&gt;
  
      &lt;/div&gt;
  
  &lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>