Title1

Title2

Title3

17-3 CKEDITOR 網頁編輯器 用法

一、op_form()


	$DirName = "icon";
	mk_dir(WEB_PATH . "/uploads/{$DirName}");
	mk_dir(WEB_PATH . "/uploads/{$DirName}/image");
	mk_dir(WEB_PATH . "/uploads/{$DirName}/flash");
	include_once WEB_PATH . "/class/ck.php";
	$fck = new CKEditor($DirName, "content", $row['content']);
	$fck->setHeight(350);
	$row['content'] = $fck->render();

二、op_form樣板
 


        <div class="row"> 
          <div class="col-md-12">
            <div class="form-group">
              <label>內容</label>
              <{$row.content}>
            </div>
          </div>          
        </div>

三、多欄存成一欄的過濾方法


  // $content['icon'] = $mysqli->real_escape_string($_POST['icon']);
  // $content['summary'] = $mysqli->real_escape_string($_POST['summary']);
  // $content['content'] = $mysqli->real_escape_string($_POST['content']);
  //$_POST['content'] = json_encode($content, JSON_NUMERIC_CHECK | JSON_UNESCAPED_UNICODE);
  $content['icon'] = $_POST['icon'];
  $content['summary'] = $_POST['summary'];
  $content['content'] = $_POST['content'];

  $content = json_encode($content, JSON_NUMERIC_CHECK | JSON_UNESCAPED_UNICODE);

  $_POST['content'] = $mysqli->real_escape_string($content);

四、單筆撈出

這筆不要過濾
$row['content'] = $content['content']; // 轉換雙引號和單引號


########################################
#取得單筆記錄
########################################
function get_creative_nav($sn = "") {
	global $mysqli;
	if (!$sn) {
		redirect_header("index.php", 3000, "查詢新聞資料錯誤!!");
	}

	$sql = "select *
          from `creative_nav`
          where `sn`='{$sn}' and `kind`= 'icon_home'";
	$result = $mysqli->query($sql) or die(printf("Error: %s <br>" . $sql, $mysqli->sqlstate));
	$row = $result->fetch_assoc();

	#過濾撈出資料
	$row['sn'] = intval($row['sn']);
	//http://www.w3school.com.cn/php/func_string_htmlspecialchars.asp
	$row['title'] = htmlspecialchars($row['title'], ENT_QUOTES); // 轉換雙引號和單引號
	$row['url'] = htmlspecialchars($row['url'], ENT_QUOTES); // 轉換雙引號和單引號
	$row['sort'] = intval($row['sort']);
	$row['enable'] = intval($row['enable']);
	$row['target'] = intval($row['target']);

	$content = json_decode($row['content'], true); //(PHP 5 >= 5.2.0 true=>array

	$row['icon'] = htmlspecialchars($content['icon'], ENT_QUOTES); // 轉換雙引號和單引號
	$row['summary'] = htmlspecialchars($content['summary'], ENT_QUOTES); // 轉換雙引號和單引號
	$row['content'] = $content['content']; // 轉換雙引號和單引號

	return $row;
}