Aşağıdaki kodları http://d.hatena.ne.jp/dix3/20081002/1222899116 vardır ve kodları iyi çalışıyoruz.
Bu CodeIgniter'daki snoopy kullanarak bir örnektir.
Q1. Ben kullanamıyorum söylemek düzeltmek muyum,
$this -> load -> library('snoopy')
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?
if ( ! class_exists('Snoopy'))
{
require_once(APPPATH.'libraries/Snoopy'.EXT);
}
Q2. Neden yazar kullanıyor musunuz
$to_specialchars=true
Bu için gereklidir?
Q3. Eğer AppPath ve EXT açıklayabilir.
APPPATH.'libraries/Snoopy'.EXT
Ben php.net onu teslim ama ben bulamadım. EXT uzantısı olmalı, ama her yerde kullanabilirim?
Şimdiden teşekkürler.
Ben uygulama / kütüphane / Snoopy.php bir snoopy var
Ben uygulama / kütüphane / Snoopy.php var
<?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 -> c = new Snoopy();
}
function getWebHtml($url="",$to_specialchars=true){
$this ->c -> fetch( $url );
$str = mb_convert_encoding( (string) $this -> c -> results,"UTF-8","auto");
return ($to_specialchars) ? htmlspecialchars($str , ENT_QUOTES , "UTF-8" ) : $str ;
}
function getWebText($url="",$to_specialchars=true){
$this -> c -> fetchtext( $url );
$str = mb_convert_encoding( (string) $this -> c -> results,"UTF-8","auto");
return ($to_specialchars) ? htmlspecialchars($str , ENT_QUOTES , "UTF-8" ) : $str ;
}
function getWebLinks($url=""){
$this -> c -> fetchlinks( $url );
return (array) $this-> c -> results ;
}
function getWebLinksText($url="",$delimiter="<br>"){
$arr = $this-> getWebLinks($url) ;
$ret ="";
foreach($arr as $k => $v){
$ret .= $v . $delimiter ;
}
return $ret;
}
} //endofclass
/* End of file Scraping.php */
/* Location: ./application/libraries/Scraping.php */
?>
Ben bir denetleyicisi uygulama / denetleyici / mytasklist.php var
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Mytasklist extends Controller {
function Mytasklist()
{
parent :: Controller();
$this -> load -> helper( 'url' );
}
function index()
{
$data = "";
$this -> _SetTpl( $data );
}
function _SetTpl( $data )
{
$this -> load -> library("scraping");
$data["scraping"]["text"] = $this-> scraping -> getWebText("http://www.example.com/");
$data["scraping"]["html"] = $this-> scraping -> getWebHtml("http://www.example.com/");
$data["scraping"]["link"] = $this-> scraping -> getWebLinksText("http://www.example.com/","\n");
$tpl["page_title"] = "Welcome";
$tpl["main_content"] = $this -> load -> view( 'tasklist_view', $data , true );
$this -> load -> view( 'base_view', $tpl );
}
}
Ve ben bir görünüm, başvuru / view / base_view.php var
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<meta name="keywords" content="keyword here" />
<meta name="description" content="description here" />
<title><?php if(isset($page_title)){echo $page_title ;}?></title>
<?php if(isset($xajax_js)){echo $xajax_js ;}?>
<link href="http://127.0.0.1/ci_day4/css/mystyle.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="container">
<div id="rightblock">
<div id="content">
<?=$main_content?>
</div>
</div>
</div>
</body>
</html>