BloggerAds廣告

相關文章

2016年8月22日 星期一

Solve Error: Version required to extract this entry not supported (788) on SWC

to solve this issue


  1. rename your xxxx.swc to xxxx.zip
  2. unzip it
  3. rezip it
  4. rename .zip back to .swc


done~ : D

2016年1月7日 星期四

remove  BOM

http://stackoverflow.com/questions/10290849/how-to-remove-multiple-utf-8-bom-sequences-before-doctype

credits to Jasonhao

//Remove UTF8 Bom

function remove_utf8_bom($text)
{
$bom = pack('H*','EFBBBF');
$text = preg_replace("/^$bom/", '', $text);
return $text;
}

2015年6月26日 星期五

php pass data to include_once() require_once()

The following code shows how to pass params to included files in php
it works also in the following functions:
include()
include_once()
require()
require_once()


application.php
Using an Associative array to carry variables would be an ideal option.
<?php
$m = new Main();

$items = array(
 'name'=> 'John Doe',
 'items'=>array('stone', 'knife', 'card', 'etc...')
);

$m->loadViewWithParams('item_list_view.php', $items);
?>

Main.php
For variables which visibles to the line above the include(), they also visibles to the included file.
We simply create variables just above the include() just the way that many people do so.
Since we've passed an associative array to loadViewWithParams(), we will break the array into variables in runtime.
<?php
class Main {
/**
*
*@param $path string the file path to load.
*@param $params array an associative array which carry data to the loaded file.
*/
  public function loadViewWithParams($path, $params = array()){
    //we use a foreach to parse the array to variables
    foreach ($params as $key => $value ) {
      $$key = $value;
    }

    include_once($path);
  }
}
?>

item_list_view.php
consider the application.php above
the loadViewWithParams() method converted the array into variables
now both $name and $item were passed to the included file
<div>
 <h1>Welcome, <?php echo $name; ?> </h1>
 here are your items
 <ul>
  <?php foreach($myItemList as $item): ?>
  <li><?php echo $item; ?></li>
  <?php endforeach; ?>
 <ul>
</div>