PHP中批量更换静态html(命令行下运营PHP卡塔尔

eg.这个是静态化首页的,首先先要把需要静态化的内容填充到模版中去,未经博主允许不得转载,版权声明,PDO 类)、Model.class.php(PDO数据库操作类)、index.php(执行文件),config.inc.php(配置文件)、Db.class.php(数据库

率先先要把须求静态化的剧情填充到模版中去

 

鲜明,大多数网址的音讯资源音信或商品新闻都是静态页面。那样做的裨益首若是为着:1、加速访谈速度,制止过多的操作数据库;2、SEO优化,便于寻觅引擎收音和录音。

#eg.这一个是静态化首页的

<?php
function new_htmlspecialchars($string)
{
 return is_array($string) ? array_map(‘new_htmlspecialchars’,
$string) : htmlspecialchars($string, ENT_QUOTES);
}

本示例围绕 CMS 系统的静态页面方案出发,体现批量变动静态 html 作用。
注:本文程序只可以在 Windows 的 DOS 或 Linux 下实践 PHP 命令来运作。
本示例主要有4个文件:config.inc.php(配置文件)、Db.class.php(数据库
PDO 类)、Model.class.php(PDO数据库操作类)、index.php(实行文书)
config.inc.php

function staticIndex(){

function new_addslashes($string)
{
 if(!is_array($string)) return addslashes($string);
 foreach($string as $key => $val) $string[$key] =
new_addslashes($val);
 return $string;
}

复制代码 代码如下:
header(‘Content-Type:text/html;Charset=utf-8’);
date_default_timezone_set(‘PRC’);
define(‘ROOT_PATH’, dirname(apizl_file)); // 根目录
define(‘DB_DSN’, ‘mysql:host=localhost;dbname=article’); // MySQL 的
PDO dsn
define(‘DB_USERubicon’, ‘root’State of Qatar; // 数据库客商名
define(‘DB_PWD’, ‘1715544’卡塔尔国; //
数据库密码(请您依据实际处境自行设定)
function __autoload($className) {
 require_once ROOT_PATH . ‘/includes/’. ucfirst($className)
.’.class.php’;
}
?>

$newslist =
$article->getArticles(null,54,’DESC’,1,6,false,1,2,”,0,0,1);
   if($newslist){
    foreach($newslist as $k=>$v){
     $newslist[$k][‘title_all’] = $v[‘title’];
     $newslist[$k][‘title’] = cutstr($v[‘title’],36,’…’);
    }
    $smarty->assign(‘newslist’,$newslist);
   }

function new_stripslashes($string)
{
 if(!is_array($string)) return stripslashes($string);
 foreach($string as $key => $val) $string[$key] =
new_stripslashes($val);
 return $string;
}

Db.class.php

$content = ”;
$content =
$smarty->fetch(‘index.html’,trueState of Qatar;//那是斯Matty自带的更动静态页面包车型客车函数
$static_name =
ROOT_PATH.’index.html’;//那是生成静态页面当前的路子文件
fopen($static_name,’a’卡塔尔(قطر‎;//展开那一个文件
@file_put_contents($static_name,$contentState of Qatar;//最终写进去
return true;
}

function filter_xss($string, $allowedtags = ”, $disabledattributes =
array(‘onabort’, ‘onactivate’, ‘onafterprint’, ‘onafterupdate’,
‘onbeforeactivate’, ‘onbeforecopy’, ‘onbeforecut’, ‘onbeforedeactivate’,
‘onbeforeeditfocus’, ‘onbeforepaste’, ‘onbeforeprint’, ‘onbeforeunload’,
‘onbeforeupdate’, ‘onblur’, ‘onbounce’, ‘oncellchange’, ‘onchange’,
‘onclick’, ‘oncontextmenu’, ‘oncontrolselect’, ‘oncopy’, ‘oncut’,
‘ondataavaible’, ‘ondatasetchanged’, ‘ondatasetcomplete’, ‘ondblclick’,
‘ondeactivate’, ‘ondrag’, ‘ondragdrop’, ‘ondragend’, ‘ondragenter’,
‘ondragleave’, ‘ondragover’, ‘ondragstart’, ‘ondrop’, ‘onerror’,
‘onerrorupdate’, ‘onfilterupdate’, ‘onfinish’, ‘onfocus’, ‘onfocusin’,
‘onfocusout’, ‘onhelp’, ‘onkeydown’, ‘onkeypress’, ‘onkeyup’,
‘onlayoutcomplete’, ‘onload’, ‘onlosecapture’, ‘onmousedown’,
‘onmouseenter’, ‘onmouseleave’, ‘onmousemove’, ‘onmoveout’,
‘onmouseover’, ‘onmouseup’, ‘onmousewheel’, ‘onmove’, ‘onmoveend’,
‘onmovestart’, ‘onpaste’, ‘onpropertychange’, ‘onreadystatechange’,
‘onreset’, ‘onresize’, ‘onresizeend’, ‘onresizestart’, ‘onrowexit’,
‘onrowsdelete’, ‘onrowsinserted’, ‘onscroll’, ‘onselect’,
‘onselectionchange’, ‘onselectstart’, ‘onstart’, ‘onstop’, ‘onsubmit’,
‘onunload’))
{
 if(is_array($string))
 {
  foreach($string as $key => $val) $string[$key] =
filter_xss($val, ALLOWED_HTMLTAGS);
 }
 else
 {
  $string = preg_replace(‘/\s(‘.implode(‘|’,
$disabledattributes).’).*?([\s\>])/’, ‘\\2’,
preg_replace(‘/<(.*?)>/ie’,
“‘<‘.preg_replace(array(‘/javascript:[^\”\’]*/i’,
‘/(“.implode(‘|’, $disabledattributes).”)[ \\t\\n]*=[
\\t\\n]*[\”\’][^\”\’]*[\”\’]/i’, ‘/\s+/’), array(”,
”, ‘ ‘), stripslashes(‘\\1’)) . ‘>'”, strip_tags($string,
$allowedtags)));
 }
 return $string;
}

复制代码 代码如下:
// 连接数据库
class Db {
 static public function getDB() {
  try {
   $pdo = new PDO(DB_DSN, DB_USER, DB_PWD);
   $pdo->setAttribute(PDO::ATTR_PE奥迪Q5SISTENT, trueState of Qatar; //
设置数据库连接为长久连接
   $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTIONState of Qatar; 
// 设置抛出荒谬
   $pdo->setAttribute(PDO::ATTR_ORACLE_NULLS, true卡塔尔;  //
设置当字符串为空转换为 SQL 的 NULL
   $pdo->query(‘SET NAMES utf8’卡塔尔国;  // 设置数据库编码
  } catch (PDOException $e) {
   exit(‘数据库连接错误,错误音讯:’. $e->getMessage(State of Qatar卡塔尔(قطر‎;
  }
  return $pdo;
 }
}
?>

//静态化列表页,按项目分歧经行静态化

function safe_replace($string)
{
 $string = str_replace(‘%20’,”,$string);
 $string = str_replace(‘%27’,”,$string);
 $string = str_replace(‘*’,”,$string);
 $string = str_replace(‘”‘,’"’,$string);
 $string = str_replace(“‘”,”,$string);
 $string = str_replace(“\””,”,$string);
 $string = str_replace(‘//’,”,$string);
 $string = str_replace(‘;’,”,$string);
 $string = str_replace(‘<‘,'<‘,$string);
 $string = str_replace(‘>’,’>’,$string);
 $string = str_replace(‘(‘,”,$string);
 $string = str_replace(‘)’,”,$string);
 $string = str_replace(“{“,”,$string);
 $string = str_replace(‘}’,”,$string);
 return $string;
}

Model.class.php

function staticContent(卡塔尔国{//须要静态话的条数
  $ids = array();//获取具备的剧情
   $ids =
$this->getListIds(State of Qatar;//这一个措施获得具备的源委,上边红字部分对应它的法子
   foreach($ids as $k=>$value){
    //echo $value[‘catid’];
   
if(!file_exists(ROOT_PATH.’demo/’卡塔尔国卡塔尔国{//判别根目录下边有未有这些文件夹,若无则创制demo这几个文件夹
     mkdir(ROOT_PATH.’demo/’);
    }
    
if(!file_exists(ROOT_PATH.’demo/’.$value[‘catid’]卡塔尔卡塔尔国{//判别那些文件夹上面有未有相应的类型文件夹
      mkdir(ROOT_PATH.’demo/’.$value[‘catid’]);
      }
     $html_content = $this->getDemoContent($value[‘demoid’]);
     $static_name =
ROOT_PATH.’demo/’.$value[‘catid’].’/’.$value[‘demoid’].’.html’;
     fopen($static_name,’a’);
     @file_put_contents($static_name,$html_content);
    }
  return true;
  }

function filter_word($data = ”)
{
 global $PHPCMS;
 $filter_word = trim($PHPCMS[‘filter_word’]);
 if(!$filter_word || (!$data && !$_GET && !$_POST)) return false;
 $filter_word = array_filter(array_map(‘trim’, explode(“\n”,
$filter_word)));
    if(!$filter_word) return false;
 $pattern = str_replace(‘\*’, ‘.*’, implode(‘|’,
array_map(‘preg_quote’, $filter_word)));
 $data = array2string($_REQUEST);
 if($pattern && preg_match(“/($pattern)/”, $data, $m))
 {
  $pattern_word = $m[0];
  define(‘ILLEGAL_WORD’, $pattern_word);
  unset($m[0]);
  $word = implode(‘ ‘, $m);
  $logdata = array(TIME, IP, $word, $pattern_word);
  $logfile = PHPCMS_ROOT.’data/filterlog/’.date(‘Ym’, TIME).’.csv’;
  $fp = fopen($logfile, ‘a’);
  fputcsv($fp, $logdata);
  fclose($fp);
  return true;
 }
 return false;
}

复制代码 代码如下:
// 操作 SQL
class Model {
 /**
  * SQL 增加和删除改操作,再次来到受影响的行数
  * @param string $sql
  * @return int
  */
 public function aud($sql) {
  try {
   $pdo = Db::getDB();
   $row = $pdo->exec($sql);
  } catch (PDOException $e) {
   exit($e->getMessage());
  }
  return $row;
 }

  //拿出须要静态化的页面ID
function getListIds(){
   $sql = “select * from {$this->tablepre}demo order by demoid
asc”;
   $rs = $this->db->getAll($sql);
   if($rs){
     return $rs;
   }else{
   return false;
   }
}

function format_textarea($string)
{
 return nl2br(str_replace(‘ ‘, ‘ ‘, htmlspecialchars($string)));
}

 /**
  * 重回全体数码,重回 PDOStatement 对象
  * @param string $sql
  * @return PDOStatement
  */
 public function getAll($sql) {
  try {
   $pdo = Db::getDB();
   $result = $pdo->query($sql);
   return $result;
  } catch (PDOException $e) {
   exit($e->getMessage());
  }
 }
}
?>

//content单页静态化
function getDemoContent($id){
   global $smarty,$view_templates,$admin_templates;
   loadModel(array(‘demo’));
   $demo = new demo();
   $content = ”;
   $smarty->template_dir = ROOT_PATH.$view_templates;
   $getMobanOne = $this->getMobanDetail($id);
   $mobandetail = $demo->MobanList($id);
    foreach($mobandetail as $k=>$v){
       $smarty->assign($k,$v);
       }
   $this->catid = $getMobanOne[‘catid’];
   $smarty->assign(‘pre_title’,$mobandetail[‘membername’]);
   $smarty->assign(‘mobandetail’,$mobandetail);
   $content = $smarty->fetch(‘demo_show.html’,true);
   $smarty->template_dir = ROOT_PATH.$view_templates;
   return $content;
}

function format_js($string, $isjs = 1)
{
 $string = addslashes(str_replace(array(“\r”, “\n”), array(”, ”),
$string));
 return $isjs ? ‘document.write(“‘.$string.'”);’ : $string;
}

index.php

原先用的可怜生成静态页面每一趟都要试行PHP文件,然后技术生成,现在本人写的那几个就是由人说了算的,想生成就生成,很有益于,希望能给我们带来有利,祝我们职业欢娱。

if(!function_exists(‘file_put_contents’))
{
 define(‘FILE_APPEND’, 8);
 function file_put_contents($file, $data, $append = ”)
 {
  $mode = $append == ” ? ‘wb’ : ‘ab’;
  $fp = @fopen($file, $mode) or exit(“Can not open file $file !”);
  flock($fp, LOCK_EX);
  $len = @fwrite($fp, $data);
  flock($fp, LOCK_UN);
  @fclose($fp);
  return $len;
 }
}

复制代码 代码如下:
require_once ‘./config.inc.php’;
$m = new Model();
$ids = $m->getAll(“SELECT id FROM article ORDER BY id ASC”);
foreach ($ids as $rowIdArr) {
 $idStr .= $rowIdArr[‘id’].’,’;
}
$idStr = rtrim($idStr, ‘,’卡塔尔; // 全数随笔的 ID 号会集
$idArr = explode(‘,’, $idStr卡塔尔国; // 分割成数组
// 下边包车型地铁次第循环生成静态页面
foreach ($idArr as $articleId) {
 $re = $m->getAll(“SELECT id,title,date,author,source,content FROM
article WHERE id =”. $articleId卡塔尔国; // $re
为每篇文章的内容,注意:其品种为:PDOStatement
 $article = array(卡塔尔; // $article
为一个数组,保存每篇小说的title、date、author、content、source
 foreach ($re as $r) {
  $article = array(
     ‘title’=>$r[‘title’],
     ‘date’=>$r[‘date’],
     ‘author’=>$r[‘author’],
     ‘source’=>$r[‘source’],
     ‘content’=>$r[‘content’]
    );
 }
 $articlePath = ROOT_PATH. ‘/article’; // $articlePath
为静态页面放置的目录
 if (!is_dir($articlePath卡塔尔(قطر‎State of Qatar mkdir($articlePath, 0777卡塔尔国; //
检查目录是不是留存,不设有则创制
 $fileName = ROOT_PATH . ‘/article/’ . $articleId . ‘.html’; //
$fileName 生成的静态文件名,格式:随笔ID.html(主键ID不容许冲突)
 $articleTemPath = ROOT_PATH . ‘/templates/article.html’; //
$articleTemPath 小说模板路线
 $articleContent = file_get_contents($articleTemPathState of Qatar; //
获取模板里面包车型客车内容
 // 对模板里面安装的变量进行替换。即比如:把模版里面包车型地铁替换到数据Curry读取的 title,替换实现赋值给变量 $articleContent
 $articleContent = getArticle(array_keys($article), $articleContent,
$article);
 $resource = fopen($fileName, ‘w’);
 file_put_contents($fileName, $articleContent); // 写入 HTML 文件
}

if(!function_exists(‘http_build_query’))
{
    function http_build_query($data, $prefix = null, $sep = ”, $key =
”)
 {
        $ret = array();
  foreach((array)$data as $k => $v)
  {
   $k = urlencode($k);
   if(is_int($k) && $prefix != null)
   {
    $k = $prefix.$k;
   }
   if(!empty($key)) {
    $k = $key.”[“.$k.”]”;
   }
   if(is_array($v) || is_object($v))
   {
    array_push($ret,http_build_query($v,””,$sep,$k));
   }
   else
   {
    array_push($ret,$k.”=”.urlencode($v));
   }
  }
        if(empty($sep))
  {
            $sep = ini_get(“arg_separator.output”);
        }
        return implode($sep, $ret);
    }
}

/**
 * get阿特icle($arr, $content, $articleState of Qatar 对模板进行轮番操作
 * @param array $arr 替换变量数组
 * @param string $content 模板内容
 * @param array $article 每篇文章内容数组,格式:array(‘title’=>xx,
‘date’=>xx, ‘author’=>xx, ‘source’=>xx, ‘content’=>xx卡塔尔国;
 */
function getArticle($arr, $content, $article) {
 // 循环替换
 foreach ($arr as $item) {
  $content = str_replace(”, $article[$item], $content);
 }
 return $content;
}
?>

if(!function_exists(‘image_type_to_extension’))
{
    function image_type_to_extension($type, $dot = true)
    {
        $e = array ( 1 => ‘gif’, ‘jpeg’, ‘png’, ‘swf’, ‘psd’, ‘bmp’
,’tiff’, ‘tiff’, ‘jpc’, ‘jp2’, ‘jpf’, ‘jb2’, ‘swc’, ‘aiff’, ‘wbmp’,
‘xbm’);
        $type = intval($type);
        if (!$type)
  {
            trigger_error( ‘File Type is null…’, E_USER_NOTICE );
            return null;
        }
        if(!isset($e[$type]))
  {
            trigger_error( ‘Image type is wrong…’, E_USER_NOTICE
);
            return null;
        }
        return ($dot ? ‘.’ : ”) . $e[$type];
    }
}

 运维截图(Windows 的 DOS 为例) 
图片 1       
运作完结截图: 

if(!function_exists(‘array_intersect_key’))
{
 function array_intersect_key($isec, $keys)
 {
  $argc = func_num_args();
  if ($argc > 2)
  {
   for ($i = 1; !empty($isec) && $i < $argc; $i++)
   {
    $arr = func_get_arg($i);
    foreach (array_keys($isec) as $key)
    {
     if (!isset($arr[$key]))
     {
      unset($isec[$key]);
     }
    }
   }
   return $isec;
  }
  else
  {
   $res = array();
   foreach (array_keys($isec) as $key)
   {
    if (isset($keys[$key]))
    {
     $res[$key] = $isec[$key];
    }
   }
   return $res;
  }
 }
}

图片 2

if(!function_exists(‘json_encode’))
{
 function json_encode($string)
 {
  require_once ‘json.class.php’;
  $json = new json();
  return $json->encode($string);
 }
}

运营2分钟左右就足以生成 9000多 html。

if(!function_exists(‘json_decode’))
{
 function json_decode($string,$type = 1)
 {
  require_once ‘json.class.php’;
  $json = new json();
  return $json->decode($string,$type);
 }
}

源于Lee.的专辑 转发注明出处!!!

if(!function_exists(‘iconv’))
{
 function iconv($in_charset, $out_charset, $str)
 {
  if(function_exists(‘mb_convert_encoding’))
  {
   return mb_convert_encoding($str, $out_charset, $in_charset);
  }
  else
  {

   require_once ‘iconv.func.php’;
   $in_charset = strtoupper($in_charset);
   $out_charset = strtoupper($out_charset);
   if($in_charset == ‘UTF-8’ && ($out_charset == ‘GBK’ ||
$out_charset == ‘GB2312’))
   {
    return utf8_to_gbk($str);
   }
   if(($in_charset == ‘GBK’ || $in_charset == ‘GB2312’) &&
$out_charset == ‘UTF-8’)
   {
    return gbk_to_utf8($str);
   }
   return $str;
  }
 }
}

function str_charset($in_charset, $out_charset, $str_or_arr)
{
 if(is_array($str_or_arr))
 {
  foreach($str_or_arr as $k=>$v)
  {
   $str_or_arr[$k] = str_charset($in_charset, $out_charset,
$v);
  }
 }
 else
 {
  $str_or_arr = iconv($in_charset, $out_charset, $str_or_arr);
 }
 return $str_or_arr;
}

function stripstr($str)
{
 return str_replace(array(‘..’, “\n”, “\r”), array(”, ”, ”),
$str);
}

if(!function_exists(‘fputcsv’))
{
 function fputcsv(&$fp, $array, $delimiter = ‘,’, $enclosure = ‘”‘)
 {
  $data = $enclosure.implode($enclosure.$delimiter.$enclosure,
$array).$enclosure.”\n”;
  return fwrite($fp, $data);
 }
}

function random($length, $chars = ‘0123456789’)
{
 $hash = ”;
 $max = strlen($chars) – 1;
 for($i = 0; $i < $length; $i++)
 {
  $hash .= $chars[mt_rand(0, $max)];
 }
 return $hash;
}

function set_cookie($var, $value = ”, $time = 0)
{
 $time = $time > 0 ? $time : ($value == ” ? PHP_TIME – 3600 : 0);
 $s = $_SERVER[‘SERVER_PORT’] == ‘443’ ? 1 : 0;
 $var = COOKIE_PRE.$var;
 $_COOKIE[$var] = $value;
 if(is_array($value))
 {
  foreach($value as $k=>$v)
  {
   setcookie($var.'[‘.$k.’]’, $v, $time, COOKIE_PATH, COOKIE_DOMAIN,
$s);
  }
 }
 else
 {
  setcookie($var, $value, $time, COOKIE_PATH, COOKIE_DOMAIN, $s);
 }
}

function get_cookie($var)
{
 $var = COOKIE_PRE.$var;
 return isset($_COOKIE[$var]) ? $_COOKIE[$var] : false;
}

function content_set($contentid, $field, $data)
{
 return @file_put_contents(content_file($contentid, $field),
$data);
}

function content_get($contentid, $field)
{
 return @file_get_contents(content_file($contentid, $field));
}

function content_del($contentid, $field)
{
 return @unlink(content_file($contentid, $field));
}

function content_file($contentid, $field)
{
 $id = str_pad($contentid, 4, ‘0’, STR_PAD_LEFT);
 return CONTENT_ROOT.$field.’/’.substr($id, 0, 2).’/’.substr($id, 2,
2).’/’.$contentid.’.txt’;
}

function content_init($field)
{
 @set_time_limit(300);
 @mkdir(CONTENT_ROOT.$field, 0777);
 for($i=1; $i<=9999; $i++)
 {
  $id = str_pad($i, 4, ‘0’, STR_PAD_LEFT);
  $dir1 = CONTENT_ROOT.$field.’/’.substr($id, 0, 2);
  $dir2 = $dir1.’/’.substr($id, 2, 2);
  @mkdir($dir1, 0777);
  @mkdir($dir2, 0777);
 }
 return true;
}

function menu($parentid, $code = ”)
{
 global $db, $_userid, $_roleid, $_groupid;
 $code = str_replace(‘”‘, ‘\”‘, $code);
 $where = $parentid == 99 ? “AND userid=$_userid” : ”;
 $menus = $db->select(“SELECT * FROM `”.DB_PRE.”menu` WHERE
`parentid`=’$parentid’ $where ORDER BY `listorder`,`menuid`”,
‘menuid’);
 if($code)
 {
  foreach($menus as $m)
  {
   extract($m);
   if(($roleids && defined(‘IN_ADMIN’) && !check_in($_roleid,
$roleids)) || ($groupids && !defined(‘IN_ADMIN’) &&
!check_in($_groupid, $groupids))) continue;
   eval(“\$menu .= \”$code\”;”);
  }
  $menus = $menu;
 }
 return $menus;
}

function url($url, $isabs = 0)
{
 if(strpos($url, ‘://’) !== FALSE || $url[0] == ‘?’) return $url;
 if($isabs || defined(‘SHOWJS’))
 {
  $url = strpos($url, PHPCMS_PATH) === 0 ? SITE_URL.substr($url,
strlen(PHPCMS_PATH)) : SITE_URL.$url;
 }
 else
 {
  $url = strpos($url, PHPCMS_PATH) === 0 ? $url : PHPCMS_PATH.$url;
 }
 return $url;
}

function is_ie()
{
 $useragent = strtolower($_SERVER[‘HTTP_USER_AGENT’]);
 if((strpos($useragent, ‘opera’) !== false) || (strpos($useragent,
‘konqueror’) !== false)) return false;
 if(strpos($useragent, ‘msie ‘) !== false) return true;
 return false;
}

function is_websearch()
{
 if(!defined(‘IS_WEBSEARCH’))
 {
  $useragent = strtolower($_SERVER[‘HTTP_USER_AGENT’]);
  $browsers = ‘msie|netscape|opera|konqueror|mozilla’;
  $spiders =
‘bot|spider|google|isaac|surveybot|baiduspider|yahoo|sohu-search|yisou|3721|qihoo|daqi|ia_archiver|p.arthur|fast-webcrawler|java|microsoft-atl-native|turnitinbot|webgather|sleipnir|msn’;
  if(preg_match(“/($browsers)/”, $_SERVER[‘HTTP_USER_AGENT’]))
  {
   define(‘IS_WEBSEARCH’, FALSE);
  }
  elseif(preg_match(“/($spiders)/”,
$_SERVER[‘HTTP_USER_AGENT’]))
  {
   define(‘IS_WEBSEARCH’, TRUE);
  }
  else
  {
   define(‘IS_WEBSEARCH’, FALSE);
  }
 }
 return IS_WEBSEARCH;
}

function is_date($ymd, $sep=’-‘)
{
 if(empty($ymd)) return FALSE;
 list($year, $month, $day) = explode($sep, $ymd);
 return checkdate($month, $day, $year);
}

function is_email($email)
{
 return strlen($email) > 6 &&
preg_match(“/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/”, $email);
}

function str_exists($haystack, $needle)
{
 return !(strpos($haystack, $needle) === FALSE);
}