Hướng dẫn làm web bán hàng bằng php từ a- z-phần 3
Hướng dẫn làm web bán hàng bằng php từ a- z-phần 3
Tiếp theo phần này tôi đi vào file hàm để giải quyết các thuật toán
include(“ham/ham.php”); // dùng để lấy hàm
Chúng ta tạo 1 forder ham bằng với file index.php trong forder đó tạo 1 file tên là ham.php
Code của ham.php như sau :
[sourcecode language=”plain”]</pre>
<?php
function chong_pha_hoai()
{
}
function chongphahoai()
{
}
function ma_hoa($c)
{
$q="yhjkf_89!f@_{sa]}___";
$c_2=$q.$c;
return md5(md5(md5($c_2)));
}
<pre></pre>
<h3><span style="font-size: 14pt;">mau ckeditter</span></h3>
<pre></pre>
function mau_fckeditor()
{
$mau=thong_so_2(22);
$mau_2=thong_so_2(23);
?>
oFCKeditor.Config["EditorAreaStyles"] = "body {background:<?php echo $mau; ?>;color:<?php echo $mau_2; ?>;}" ;
<?php
}
function mau_fckeditor_2()
{
$tuy_chon=thong_so_2(24);
if($tuy_chon=="bat")
{
?>
<br>
<div style="margin:0px 3px" >
<a href="?thamso=doi_mau_fckeditor" target="_blank" class="link_l1" >Đổi màu khung nhập liệu fckeditor bên dưới , click here</a>
</div>
<br>
<?php
}
}
//$a=ma_hoa("8582270");echo $a."<hr>";
<pre></pre>
<h3><span style="font-size: 14pt;">chuỗi html thân thiện</span></h3>
<pre></pre>
function source_html_xuong_dong($chuoi)
{
$chuoi=str_replace(">",">\n",$chuoi);
return $chuoi;
}
function full_url()
{
$s = empty($_SERVER["HTTPS"]) ? ” : ($_SERVER["HTTPS"] == "on") ? "s" : "";
$sp = strtolower($_SERVER["SERVER_PROTOCOL"]);
$protocol = substr($sp, 0, strpos($sp, "/")) . $s;
$port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
return $protocol . "://" . $_SERVER[‘SERVER_NAME’] . $port . $_SERVER[‘REQUEST_URI’];
}
<h3><span style="font-size: 14pt;">//echo full_url()."<hr>";</span></h3>
function thongbao($chuoi)
{
echo "<script>alert(\"$chuoi\");</script>";
}
function phat_hien_trinh_duyet()
{
$u_agent = $_SERVER[‘HTTP_USER_AGENT’];
$ub = ”;
if(preg_match(‘/MSIE/i’,$u_agent))
{
$ub = "ie";
}
elseif(preg_match(‘/Firefox/i’,$u_agent))
{
$ub = "firefox";
}
elseif(preg_match(‘/Safari/i’,$u_agent))
{
$ub = "safari";
}
elseif(preg_match(‘/Chrome/i’,$u_agent))
{
$ub = "chrome";
}
elseif(preg_match(‘/Flock/i’,$u_agent))
{
$ub = "flock";
}
elseif(preg_match(‘/Opera/i’,$u_agent))
{
$ub = "opera";
}
return $ub;
}
<h5><span style="font-size: 14pt;">loại bỏ khoảng trắng</span></h5>
function mang_bo_khoang_trang_co_sap_xep($mang)
{
$mang1=array_filter($mang);
$tln=0;
foreach($mang1 as $dohoalaptrinh)
{
$mang2[$tln]=$dohoalaptrinh;
$tln++;
}
return $mang2;
}
function ham_1($mang)
{
$mang1=array_filter($mang);
$tln=0;
foreach($mang1 as $dohoalaptrinh)
{
$mang2[$tln]=$dohoalaptrinh;
$tln++;
}
<h4></h4>
return $mang2;
}
function chuyentrang($link)
{
?>
<script type="text/javascript">
window.location="<?php echo $link?>";
</script>
<?php
}
function chuyen_trang($link)
{
?>
<script type="text/javascript">
window.location="<?php echo $link?>";
</script>
<?php
}
<h4><span style="font-size: 14pt;">tra ve mang </span></h4>
function trangtruoc(){
echo "
<script type=\"text/javascript\">
window.history.back();
</script>
";
}
function trang_truoc(){
echo "
<script type=\"text/javascript\">
window.history.back();
</script>
";
}
function div_1px()
{
echo "<div style=\"width:100%;height:1px;overflow:hidden;\"></div>";
}
function div_3px()
{
echo "<div style=\"width:100%;height:3px;overflow:hidden;\"></div>";
}
function div_5px()
{
echo "<div style=\"width:100%;height:5px;overflow:hidden;\"></div>";
}
<h6>l<span style="font-size: 14pt;">ay duong dan than thien</span></h6>
function ghi_tep($duongdan,$noidung){
$fh=fopen($duongdan, ‘w’);
return fwrite($fh,$noidung);
}
function doc_tep($duongdan){
$fh=fopen($duongdan, ‘r+’);
$theData = fread($fh, filesize($duongdan));
return $theData;
}
function h1_1($chuoi)
{
?>
<center><h1 style="color:red"><?php echo $chuoi; ?></h1></center>
<?php
}
function lay_truy_van($tv)
{
return mysql_fetch_array($tv);
}
function lay_truyvan($tv)
{
return mysql_fetch_array($tv);
}
<h4><span style="font-size: 14pt;">truy vấn </span></h4>
function laytruyvan($tv)
{
return mysql_fetch_array($tv);
}
function lay_truy_van_100($tb)
{
$sql="select * from $tb where id=’1’";
$sql_1=mysql_query($sql);
$sql_2=mysql_fetch_array($sql_1);
return $sql_2;
}
function laytruyvan_100($tb)
{
$sql="select * from $tb where id=’1’";
$sql_1=mysql_query($sql);
$sql_2=mysql_fetch_array($sql_1);
return $sql_2;
}
function lay_truy_van__100($tb)
{
$sql="select * from $tb where id=’1’";
$sql_1=mysql_query($sql);
$sql_2=mysql_fetch_array($sql_1);
return $sql_2;
}
<h4><span style="font-size: 14pt;">truy vấn menu</span></h4>
function chuoi_id_menu_con($id_cha,$chuoi)
{
$tv="select * from menu where thuoc_menu=’$id_cha’ order by id";
$tv_1=mysql_query($tv);
while($tv_2=mysql_fetch_array($tv_1))
{
$chuoi=$chuoi.$tv_2[‘id’].",";
$r="select count(*) from menu where thuoc_menu=’$id_cha’";
$r_1=mysql_query($r);
$r_2=mysql_fetch_row($r_1);
if($r_2[0]!=0)
{
$chuoi=chuoi_id_menu_con($tv_2[‘id’],$chuoi);
}
}
return $chuoi;
}
function mang_id_menu_con($id_menu)
{
if($id_menu!="")
{
$chuoi=$id_menu.",";
}
else
{
$chuoi="";
}
<h3><span style="font-size: 14pt;">chuoi </span></h3>
$chuoi_id_menu_con=chuoi_id_menu_con($id_menu,$chuoi);
$mang=explode(",",$chuoi_id_menu_con);
unset($mang[count($mang)-1]);
return $mang;
}
function chuoi_union_dulieu($id_cha,$table)
{
$chuoi="";
$mang_id_menu_con=mang_id_menu_con($id_cha);
for($i=0;$i<count($mang_id_menu_con);$i++)
{
$thuoc_menu=$mang_id_menu_con[$i];
$query="select count(*) from $table where thuoc_menu=’$thuoc_menu’";
$result=mysql_query($query);
$row=mysql_fetch_row($result);
$so=$row[0];
$chuoi=$chuoi." ( select * from $table where thuoc_menu=’$thuoc_menu’ order by id desc limit 0,$so ) union ";
}
$chuoi=substr($chuoi,0,-6);
return $chuoi;
}
<h4><span style="font-size: 14pt;">sắp xếp chuỗi dữ liệu</span></h4>
function chuoi_union_dulieu_2($id_cha,$table,$sap_xep)
{
$chuoi="";
$mang_id_menu_con=mang_id_menu_con($id_cha);
for($i=0;$i<count($mang_id_menu_con);$i++)
{
$thuoc_menu=$mang_id_menu_con[$i];
$query="select count(*) from $table where thuoc_menu=’$thuoc_menu’";
$result=mysql_query($query);
$row=mysql_fetch_row($result);
$so=$row[0];
$chuoi=$chuoi." ( select * from $table where thuoc_menu=’$thuoc_menu’ order by $sap_xep limit 0,$so ) union ";
}
$chuoi=substr($chuoi,0,-6);
return $chuoi;
}
<h5><span style="font-size: 14pt;">dem du lieu</span></h5>
function dem_dulieu_vghj($id_cha,$table)
{
$chuoi="";
$mang_id_menu_con=mang_id_menu_con($id_cha);
$so_1=0;
for($i=0;$i<count($mang_id_menu_con);$i++)
{
$thuoc_menu=$mang_id_menu_con[$i];
$query="select count(*) from $table where thuoc_menu=’$thuoc_menu’";
$result=mysql_query($query);
$row=mysql_fetch_row($result);
$so=$row[0];
$so_1=$so_1+$so;
//$chuoi=$chuoi." ( select * from $table where thuoc_menu=’$thuoc_menu’ order by id desc limit 0,$so ) union ";
}
//$chuoi=substr($chuoi,0,-6);
return $so_1;
}
function xuat_link_dkl($st)
{
//if($_GET[‘trang’]==""){$_GET[‘trang’]=1;}
?>
<h5><span style="font-size: 14pt;">css cho mau sac dep</span></h5>
<style>
a.pt3
{
color:black;
text-decoration: none;
font-weight:bold;
}
a.pt3:hover
{
color:red;
text-decoration: none;
font-weight:bold;
}
</style>
<?php
echo "<center>";
if($_GET[‘trang’]!="")
{
if(ereg("&trang=",$_SERVER[‘REQUEST_URI’]))
{
$_SERVER[‘REQUEST_URI’]=str_replace("&trang=","",$_SERVER[‘REQUEST_URI’]);
$_SERVER[‘REQUEST_URI’]=substr($_SERVER[‘REQUEST_URI’],0,-strlen($_GET[‘trang’]));
$lpt=$_SERVER[‘REQUEST_URI’]."&trang=";
}
else
{
$lpt=$_SERVER[‘REQUEST_URI’]."&trang=";
}
}
else
{
$_SERVER[‘REQUEST_URI’]=str_replace("&trang=","",$_SERVER[‘REQUEST_URI’]);
$lpt=$_SERVER[‘REQUEST_URI’]."&trang=";
}
if($_GET[‘trang’]!="" and $_GET[‘trang’]!="1")
{
if($_GET[‘trang’]=="" or $_GET[‘trang’]==1)
{
$k=1;
}
else
{
$k=$_GET[‘trang’]-1;
}
$link_t=$lpt.$k;
$link_d=$lpt."1";
<h5><span style="font-size: 14pt;">nut trang trước </span></h5>
echo ‘<a href="’.$link_d.’" style="margin-right:10px" class="pt3">Đầu</a>’;
echo ‘<a href="’.$link_t.’" style="margin-right:10px" class="pt3">Trước</a>’;
}
if($_GET[‘trang’]==""){$a=1;}else{$a=$_GET[‘trang’];}
$b_1=$_GET[‘trang’]-5;$n_1=$b_1;
if($b_1<1){$b_1=1;}
$b_2=$_GET[‘trang’]+5;
if($b_2>=$st){$n_2=$b_2;$b_2=$st;}
//echo $b_1."<hr>";
if($n_1<0){$v=(-1)*$n_1;$b_2=$b_2+$v;}
if($n_2>=$st){$v_2=$n_2-$st;$b_1=$b_1-$v_2;}
if($b_1>1){echo ‘ … ‘;}
for($i=$b_1;$i<=$b_2;$i++)
{
$lpt_1=$lpt.$i;
if($i>0 && $i<=$st)
{
<h4><span style="font-size: 14pt;">neu i khong bang a</span></h4>
if($i!=$a)
{
?>
<a href="<?php echo $lpt_1; ?>" class="pt3"><?php echo $i;?> </a>
<?php
}
else
{
echo "<b style=\"color:red\">$i</b>";
}
}
}
if($b_2<$st){echo ‘ … ‘;}
if($_GET[‘trang’]!=$st && $st!=1)
{
if($_GET[‘trang’]==$st)
{
$k=$st;
}
else
<h5><span style="font-size: 14pt;">nguoc lai trang + 1</span></h5>
{
$k=$_GET[‘trang’]+1;
if($_GET[‘trang’]==""){$k=2;}
}
$link_s=$lpt.$k;
$link_cuoi=$lpt.$st;
echo ‘<a href="’.$link_s.’" style="margin-left:10px" class="pt3">Sau</a>’;
echo ‘<a href="’.$link_cuoi.’" style="margin-left:10px" class="pt3">Cuối</a>’;
}
echo "</center>";
}
function fckeditor_quanly($noi_dung="",$name="",$rong="770",$cao="",$cau_hinh_nut="")
{
if($name=="")
{
$name="noidung";
}
if($rong=="")
{
$rong=770;
}
$noi_dung=str_replace("\n","",$noi_dung);
$noi_dung=str_replace("\t","",$noi_dung);
$noi_dung=str_replace("\r","",$noi_dung);
$noi_dung=str_replace("’","\’",$noi_dung);
echo "<script type=\"text/javascript\">";
echo "var oFCKeditor = new FCKeditor(‘$name’);";
echo "oFCKeditor.BasePath = \"giaodien/fckeditor/\";";
echo "oFCKeditor.Width = $rong ;";
<h5><span style="font-size: 14pt;">neu cao khong bang rong</span></h5>
if($cao!="")
{
echo "oFCKeditor.Height = $cao ;";
}
mau_fckeditor();
//echo "oFCKeditor.Config[‘ToolbarStartExpanded’] = false ;";
if($cau_hinh_nut!="")
{
echo "oFCKeditor.ToolbarSet = ‘rut_gon_2′ ;";
}
echo "oFCKeditor.Config[\"EnterMode\"] = \"br\" ;";
echo "oFCKeditor.Value=’$noi_dung’;";
echo "oFCKeditor.Create();";
echo "document.getElementById(‘xEnter’).value = \"br\" ;";
echo "</script>";
}
<h5></h5>
<h4><span style="font-size: 14pt;">function phathien_trinhduyet()</span></h4>
{
$thongtin_trinhduyet=$_SERVER[‘HTTP_USER_AGENT’];
if(ereg("Firefox",$thongtin_trinhduyet))
{
$ten_trinhduyet="firefox";
}
else
{
if(ereg("MSIE 8.0",$thongtin_trinhduyet))
{
$ten_trinhduyet="ie8";
}
else
{
if(ereg("MSIE 7.0",$thongtin_trinhduyet))
{
$ten_trinhduyet="ie7";
}
else
{
if(ereg("MSIE 6.0",$thongtin_trinhduyet))
{
$ten_trinhduyet="ie6";
}
else
{
if(ereg("Chrome",$thongtin_trinhduyet))
{
$ten_trinhduyet="google";
}
else
{
if(ereg("Safari",$thongtin_trinhduyet))
{
$ten_trinhduyet="safari";
}
else
{
if(ereg("Opera",$thongtin_trinhduyet))
{
$ten_trinhduyet="opera";
}
else
{
$ten_trinhduyet="conlai";
}
}
}
}
}
}
}
return $ten_trinhduyet;
}
$trinh_duyet=phathien_trinhduyet();
<h3><span style="font-size: 14pt;">function empty_forder($dir)</span></h3>
<h3></h3>
{
if(!$dh = @opendir($dir)) return;
while (false !== ($obj = readdir($dh))) {
if($obj==’.’ || $obj==’..’) continue;
if (!@unlink($dir.’/’.$obj)) empty_forder($dir.’/’.$obj, true);
}
closedir($dh);
}
function getDirectoryList ($directory)
// lay danh sach file trong thu muc , tra ve mang
{
// create an array to hold directory list
$results = array();
// create a handler for the directory
$handler = opendir($directory);
// open directory and walk through the filenames
while ($file = readdir($handler)) {
// if file isn’t this directory or its parent, add it to the results
if ($file != "." && $file != "..") {
$results[] = $file;
}
}
// tidy up: close the handler
closedir($handler);
<h6><span style="font-size: 14pt;">// done!</span>
return $results;</h6>
}
function copy_forder($source, $dest){
// Simple copy for a file
if (is_file($source)) {
$c = copy($source, $dest);
chmod($dest, 0777);
return $c;
}
// Make destination directory
if (!is_dir($dest)) {
$oldumask = umask(0);
mkdir($dest, 0777);
umask($oldumask);
}
// Loop through the folder
$dir = dir($source);
while (false !== $entry = $dir->read()) {
// Skip pointers
if ($entry == "." || $entry == "..") {
continue;
}
// Deep copy directories
if ($dest !== "$source/$entry") {
copy_forder("$source/$entry", "$dest/$entry");
}
}
<h5><span style="font-size: 14pt;">// Clean up</span></h5>
$dir->close();
return true;
}
function create_file($file_name)
// tao file
{
$ourFileName = "$file_name";
$ourFileHandle = fopen($ourFileName, ‘w’) or die("can’t open file");
fclose($ourFileHandle);
}
function tr($html,$colspan=1)
{
echo "<tr>";
echo "<td colspan=\"$colspan\">";
echo $html;
echo "</td>";
echo "</tr>";
}
function o($html,$style=""){
echo "<td $style>";
echo $html;
echo "</td>";
}
<h3><span style="font-size: 14pt;">thay the ckeditter</span></h3>
function thay_the_fckeditor($nd)
{
$chuoi_1="é è ẻ ẽ ẹ ý ỳ ỷ ỹ ỵ ú ù ủ ũ ụ ư ứ ừ ử ữ ự í ì ỉ ĩ ị ó ò ỏ õ ọ ô ố ồ ổ ỗ ộ á à ả ã ạ â ấ ầ ẩ ẫ ậ ă ắ ằ ẳ ẵ ặ ê ế ể ễ ệ ơ ớ ờ ở ỡ ợ";
$chuoi_2="é è ẻ ẽ ẹ ý ỳ ỷ ỹ ỵ ú ù ủ ũ ụ ư ứ ừ ử ữ ự í ì ỉ ĩ ị ó ò ỏ õ ọ ô ố ồ ổ ỗ ộ á à ả ã ạ â ấ ầ ẩ ẫ ậ ă ắ ằ ẳ ẵ ặ ê ế ể ễ ệ ơ ớ ờ ở ỡ ợ";
<h6><span style="font-size: 14pt;">$mang_1=explode(" ",$chuoi_1);</span></h6>
$mang_2=explode(" ",$chuoi_2);
for($i=0;$i<count($mang_2);$i++)
{
<h2><span style="font-size: 14pt;">$nd=str_replace($mang_2[$i],$mang_1[$i],$nd);</span></h2>
}
$chuoi_3="É È Ẻ Ẽ Ẹ Ê Ế Ề Ể Ễ Ệ Ý Ỳ Ỷ Ỹ Ỵ Ú Ù Ủ Ũ Ụ Ư Ứ Ừ Ử Ữ Ự Í Ì Ỉ Ĩ Ị Ó Ò Ỏ Õ Ọ Ô Ố Ồ Ổ Ỗ Ộ Ơ Ớ Ờ Ở Ỡ Ợ Á À Ả Ã Ạ Â Ấ Ầ Ẩ Ẫ Ậ Ă Ắ Ằ Ẳ Ẵ Ặ";
$chuoi_4="É È Ẻ Ẽ Ẹ Ê Ế Ề Ể Ễ Ệ Ý Ỳ Ỷ Ỹ Ỵ Ú Ù Ủ Ũ Ụ Ư Ứ Ừ Ử Ữ Ự Í Ì Ỉ Ĩ Ị Ó Ò Ỏ Õ Ọ Ô Ố Ồ Ổ Ỗ Ộ Ơ Ớ Ờ Ở Ỡ Ợ Á À Ả Ã Ạ Â Ấ Ầ Ẩ Ẫ Ậ Ă Ắ Ằ Ẳ Ẵ Ặ";
<h5><span style="font-size: 14pt;"> $mang_3=explode(" ",$chuoi_3);</span></h5>
$mang_4=explode(" ",$chuoi_4);
for($i=0;$i<count($mang_3);$i++)
{
$nd=str_replace($mang_4[$i],$mang_3[$i],$nd);
}
return $nd;
}
<h6><span style="font-size: 14pt;">ham cắt chuỗi</span></h6>
function cat_chuoi_789($str,$ky_tu_dau,$ky_tu_cuoi)
{
$str=strip_tags($str);
$str=thay_the_fckeditor($str);
$split=1;
$array = array();
for ( $i=0; $i < strlen( $str ); ){
$value = ord($str[$i]);
if($value > 127){
if($value >= 192 && $value <= 223)
$split=2;
elseif($value >= 224 && $value <= 239)
$split=3;
elseif($value >= 240 && $value <= 247)
$split=4;
}else{
$split=1;
}
$key = NULL;
for ( $j = 0; $j < $split; $j++, $i++ ) {
$key .= $str[$i];
}
array_push( $array, $key );
}
$mang=$array;
//print_r($mang);echo "<hr>";
$chuoi_1="";
for($i=$ky_tu_dau;$i<$ky_tu_cuoi;$i++)
{
$chuoi_1.=$mang[$i];
}
return $chuoi_1;
}
function chong_90($ten_file_anh)
{
if(ereg(".php",$ten_file_anh))
{
thongbao("ko dc up ten anh co chuoi ki tu ‘.php’");
trangtruoc();
exit();
}
}
<h5><span style="font-size: 14pt;">kiem tra hinh hop le</span></h5>
function kiem_tra_hinh_hop_le($ten_hinh)
{
$duoi_hop_le="jpg_JPG_gif_GIF_bmp_BMP_jpeg_JPEG_png_PNG";
$mang_duoi_hinh_hop_le=explode("_",$duoi_hop_le);
$mang=explode(".",$ten_hinh);
if(count($mang)==0)
{
return "khong";
}
$duoi_hinh=$mang[count($mang)-1];
$hinh_hop_le="khong";
for($i=0;$i<count($mang_duoi_hinh_hop_le);$i++)
{
if($duoi_hinh==$mang_duoi_hinh_hop_le[$i])
{
$hinh_hop_le="co";
break;
}
}
return $hinh_hop_le;
}
function doi_usd($vnd)
{
//echo $vnd."<hr>";
$tv="select * from thong_so where ma_so=’2’";
$tv_1=mysql_query($tv);
$tv_2=mysql_fetch_array($tv_1);
$a=$tv_2[‘gia_tri’];
$usd=($vnd/$a);
$usd_1=number_format($usd,2,".",".");
//if($usd_1=0.00){$usd_1=0;}
return $usd_1;
}
<h4><span style="font-size: 14pt;">xuat trinh duyet</span></h4>
function xuat_tr($nd,$html,$width="100px")
// duoc dung trong file ‘quanly/cumchucnang/quanly_dulieu/them_dulieu_leftmenu.php’
{
echo "<tr>";
echo "<td width=\"$width\" align=\"left\" valign=\"top\"><b>$nd</b></td>";
echo "<td align=\"left\" valign=\"top\">$html</td>";
echo "</tr>";
}
function xuat_select()
{
?>
<script type="text/javascript">
function vbc(vl)
{
switch(vl)
{
case"en":
var id=document.getElementById("div_en_afc");
id.style.display="block";
var id=document.getElementById("div_vn_afc");
id.style.display="none";
break;
default:
var id=document.getElementById("div_en_afc");
id.style.display="none";
var id=document.getElementById("div_vn_afc");
id.style.display="block";
}
}
</script>
<select onchange="vbc(this.value)">
<option value="vn">Tiếng việt</option>
<option value="en">Tiếng anh</option>
</select>
<?php
}
<h4><span style="font-size: 14pt;"> //echo kiem_tra_hinh_hop_le("luan.pn");echo "<hr>";</span></h4>
//$so_dl_mnd=dem_dulieu_vghj($_GET[‘id_menu’],"sanpham");
// so du lieu trong bang du lieu thong qua bien bien get id menu
?>
<?php
class thay_the
{
function fckeditor($tu_khoa,$loai="")
{
//$tu_khoa=str_replace(‘"’,’\"’ ,$tu_khoa );
if($loai=="submit")
{
$tu_khoa=str_replace("\t","" ,$tu_khoa );
$tu_khoa=str_replace("\r","" ,$tu_khoa );
$tu_khoa=str_replace("\n","" ,$tu_khoa );
}
if($loai=="")
{
$tu_khoa=str_replace(‘"’,’\"’ ,$tu_khoa );
$tu_khoa=str_replace("\t","" ,$tu_khoa );
$tu_khoa=str_replace("\r","" ,$tu_khoa );
$tu_khoa=str_replace("\n","" ,$tu_khoa );
}
return $tu_khoa;
}
}
$class__thay_the=new thay_the;
function test($c)
{
echo "<h3 style=’color:red’ >".$c."</h3><hr>";
}
?>
<h3><span style="font-size: 14pt;">truy van du lieu</span></h3>
<?php
function truy_van($c)
{
return mysql_query($c);
}
function ten_san_pham($id)
{
$tv="select * from dulieu where id=’$id’";
$tv_1=mysql_query($tv);
$tv_2=mysql_fetch_array($tv_1);
return $tv_2[‘tieu_de’];
}
function thuoc_menu_sp($id)
{
$tv="select * from dulieu where id=’$id’";
$tv_1=mysql_query($tv);
$tv_2=mysql_fetch_array($tv_1);
return $tv_2[‘thuoc_menu’];
}
function id_cap_tren($id,$cap_lui)
{
//test($cap_lui);
//test($id);
if($cap_lui=="" or $cap_lui==1)
{
$tv="select * from menu where id=’$id’";
//test($tv);
$tv_1=mysql_query($tv);
$tv_2=mysql_fetch_array($tv_1);
//test($tv_2[‘thuoc_menu’]);
if($tv_2[‘thuoc_menu’]!="")
{
<h4><span style="font-size: 14pt;"> return $tv_2[‘thuoc_menu’];</span></h4>
}
else
{
return $tv_2[‘id’];
}
}
else
{
$tv="select * from menu where id=’$id’";
$tv_1=mysql_query($tv);
$tv_2=mysql_fetch_array($tv_1);
$cap_lui=$cap_lui-1;
return id_cap_tren($tv_2[‘thuoc_menu’],$cap_lui);
}
<h4><span style="font-size: 14pt;">kiem tra cap menu</span></h4>
}
//$h=id_cap_tren(10,2);test($h);
function h_b_1($id)
{
$thuoc_menu=thuoc_menu_sp($id);
//test($thuoc_menu);
//$id_cap_tren=id_cap_tren($thuoc_menu);
//test($id_cap_tren);
$tv="select * from menu where id=’$thuoc_menu’";
$tv_1=mysql_query($tv);
$tv_2=mysql_fetch_array($tv_1);
return $tv_2[‘ten’];
}
function h_b_2($id,$cap)
{
$thuoc_menu=thuoc_menu_sp($id);
//test($thuoc_menu);
$id_cap_tren=id_cap_tren($thuoc_menu,$cap);
//test($id_cap_tren);
$tv="select * from menu where id=’$id_cap_tren’";
$tv_1=mysql_query($tv);
$tv_2=mysql_fetch_array($tv_1);
return $tv_2[‘ten’];
}
function ten_menu($id,$ma_thong_so,$cap_lui_menu)
{
switch($ma_thong_so)
{
case "a":
test("ma a");
break;
case "b":
test("ma b");
break;
case "3":
<h4><span style="font-size: 14pt;"> // ten menu của sản phẩm</span></h4>
return h_b_1($id);
break;
case "4":
// ten menu của sản phẩm cấp trên theo $cap hay $GLOBALS[‘cap’]
return h_b_2($id,$cap_lui_menu);
break;
}
}
function read_file($file)
{
$fp = fopen($file, "r+");
$content = fread($fp, filesize($file));
return $content;
}
function write_file($duong_dan_file,$noi_dung_file)
{
$path=$duong_dan_file;
$file=fopen($path, "w");
$write=fwrite($file,$noi_dung_file);
fclose($file);
}
function thong_so($ma_so)
{
$tv="select * from thong_so where ma_so=’$ma_so’";
$tv_1=mysql_query($tv);
$tv_2=mysql_fetch_array($tv_1);
return $tv_2[‘gia_tri’];
}
function thong_so_2($ma_so)
{
$tv="select gia_tri from thong_so where id=’$ma_so’";
$tv_1=mysql_query($tv);
$tv_2=mysql_fetch_array($tv_1);
return $tv_2[‘gia_tri’];
}
<h5><span style="font-size: 14pt;">up thong do gia tri</span></h5>
function up_thong_so($ma_so,$gia_tri)
{
$up="
UPDATE `thong_so` SET
`gia_tri` = ‘$gia_tri’
WHERE `ma_so` =’$ma_so’;
";
mysql_query($up);
}
$tv="select * from thong_so where ma_so=’9’";
$tv_1=mysql_query($tv);
$tv_2=mysql_fetch_array($tv_1);
if(trim($tv_2[‘gia_tri’])=="co"){
?>
<script type="text/javascript">
function ajax_innerHTML__999(duong_dan,id)
{
if (window.XMLHttpRequest)
{
<h6><span style="font-size: 14pt;">// code for IE7+, Firefox, Chrome, Opera, Safari</span></h6>
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById(id).innerHTML=xmlhttp.responseText;
//doscript_ajax_innerHTML___1_1__dkl(xmlhttp.responseText);
//eval(alert("chao"););
}
}
//alert(+duong_dan);
xmlhttp.open("GET",duong_dan);
xmlhttp.send(null);
}
</script>
<?php
}
function include_file($file)
{
//test($file);
?>
<script type="text/javascript">
<h4><span style="font-size: 14pt;">sua file</span></h4>
function sua_file(ten_file)
{
var id_sua_file=document.getElementById("sua_file");
//alert(id_sua_file);
id_sua_file.style.display="block";
var id_tf_111=document.getElementById("tf_111");
id_tf_111.value=ten_file;
}
function c_821(file)
{
//var hhhjjjkkk=document.getElementById("hhhjjjkkk");
var duong_dan="open_file_php.php?file="+file;
//alert(duong_dan);
ajax_innerHTML__999(duong_dan,"hhhjjjkkk")
}
</script>
<?php
$full_url=full_url();
<h4><span style="font-size: 14pt;">//test($full_url);</span></h4>
if(ereg(‘thamso’,$full_url))
{
$link=$full_url."&sua_file_php=co&file=$file";
}else
{
$link=$full_url."?sua_file_php=co&file=$file";
}
$tv="select * from thong_so where ma_so=’9’";
$tv_1=mysql_query($tv);
$tv_2=mysql_fetch_array($tv_1);
if(trim($tv_2[‘gia_tri’])=="co"){
echo $file;
//echo "<span style=’margin-left:15px;color:blue;cursor:pointer’ onclick=\"sua_file(‘$file’)\">Sửa file</span>";
//echo "<span style=’margin-left:15px;color:blue;cursor:pointer’ \"><a href=’$link’>Sửa file</a></span>";
echo "<span style=’margin-left:15px;color:blue;cursor:pointer’ onclick=’c_821(\"$file\")’ \">Sửa file</span>";
echo "<hr>";
echo "<div id=’hhhjjjkkk’></div>";
}
return include($file);
}
<h4><span style="font-size: 14pt;">thong bao </span></h4>
function include_file_2($file)
{
//thongbao("vao day");
//test($file);
$base_url=$GLOBALS[‘base_url’];
//test($base_url);
$full_url=full_url();
//test($full_url);
if(ereg(‘thamso’,$full_url))
{
$link=$full_url."&sua_file_php=co&file=$file";
}else
{
$link=$full_url."?sua_file_php=co&file=$file";
}
$tv="select * from thong_so where ma_so=’9’";
//test($tv);
$tv_1=mysql_query($tv);
//var_dump($tv_1);
$tv_2=mysql_fetch_array($tv_1);
//v//ar_dump($tv_2);echo "<hr><hr><hr>";
if(trim($tv_2[‘gia_tri’])=="co"){
//thong_bao("dsaad")
//test("aas");
?>
<script>
<h2><span style="font-size: 14pt;">sua ten file</span></h2>
function sua_file(ten_file)
{
var id_sua_file=document.getElementById("sua_file");
//alert(id_sua_file);
id_sua_file.style.display="block";
var id_tf_111=document.getElementById("tf_111");
id_tf_111.value=ten_file;
}
function c_821(file)
{
<h3><span style="font-size: 14pt;">//alert(file);</span></h3>
var url_91="<?php echo $GLOBALS[‘base_url’];?>";
//var hhhjjjkkk=document.getElementById("hhhjjjkkk");
var duong_dan=url_91+"open_file_php.php?file="+file;
//alert(duong_dan);
ajax_innerHTML__999(duong_dan,"hhhjjjkkk")
}
</script>
<?php
//thong_bao("vao day");
echo $file;
//echo "<span style=’margin-left:15px;color:blue;cursor:pointer’ onclick=\"sua_file(‘$file’)\">Sửa file</span>";
//echo "<span style=’margin-left:15px;color:blue;cursor:pointer’ \"><a href=’$link’>Sửa file</a></span>";
echo "<span style=’margin-left:15px;color:blue;cursor:pointer’ onclick=’c_821(\"$file\")’ \">Sửa file</span>";
echo "<hr>";
echo "<div id=’hhhjjjkkk’></div>";
}
return include($file);
//ob_start();
//include $file;
<h6><span style="font-size: 14pt;">//return ob_get_clean();</span></h6>
}
function tat_loi()
{
ini_set(‘display_errors’,’0′);
}
function bat_loi()
{
ini_set(‘display_errors’,’1′);
}
function include_sap_xep($gt)
{
switch($gt)
{
case "menu":
include_file_2("web/quanao/cumchucnang/menu/trai.php");
break;
case "menu_p":
include_file_2("web/quanao/cumchucnang/menu/trai_p.php");
break;
case "san_pham_moi":
include_file_2("web/quanao/cumchucnang/san_pham/hop_moi.php");
break;
case "san_pham_moi_p":
include_file_2("web/quanao/cumchucnang/san_pham/hop_moi_p.php");
break;
<h4><span style="font-size: 14pt;">cat doan</span></h4>
case "qc_trai":
include_file_2("web/quanao/cumchucnang/quang_cao/trai.php");
break;
case "qc_phai":
include_file_2("web/quanao/cumchucnang/quang_cao/phai.php");
break;
case "gio_hang":
include_file_2("web/quanao/cumchucnang/gio_hang/khung.php");
break;
case "gio_hang_t":
include_file_2("web/quanao/cumchucnang/gio_hang/khung_t.php");
break;
case "ho_tro_truc_tuyen":
include_file_2("web/quanao/cumchucnang/ho_tro_truc_tuyen/ho_tro_truc_tuyen.php");
break;
case "ho_tro_truc_tuyen_t":
include_file_2("web/quanao/cumchucnang/ho_tro_truc_tuyen/ho_tro_truc_tuyen_t.php");
break;
case "tin_moi":
include_file_2("web/quanao/cumchucnang/tin_tuc/moi.php");
break;
case "tin_moi_t":
include_file_2("web/quanao/cumchucnang/tin_tuc/moi_t.php");
break;
case "hop_html_1":
include_file_2("web/quanao/cumchucnang/hop_html/hop_1.php");
break;
case "hop_html_1_t":
include_file_2("web/quanao/cumchucnang/hop_html/hop_1_t.php");
break;
}
<h5><span style="font-size: 14pt;">max</span></h5>
}
function max_id_fff($tb)
{
$tv="select max(sap_xep) from $tb";
$tv_1=mysql_query($tv);
$tv_2=mysql_fetch_row($tv_1);
return $tv_2[0];
}
function giao_dien($id)
{
$tv="select gia_tri from giao_dien where id=’$id’";
$tv_1=mysql_query($tv);
$tv_2=mysql_fetch_array($tv_1);
$m=explode("[–]",$tv_2[‘gia_tri’]);
return $m;
}
function up_giao_dien($ma_so,$gia_tri)
{
$up="
UPDATE `giao_dien` SET
`gia_tri` = ‘$gia_tri’
WHERE `id` =’$ma_so’;
";
mysql_query($up);
}
<h4><span style="font-size: 14pt;">dong</span></h4>
function gd_dong($ten,$gt,$name_input)
{
?>
<tr>
<td width="170px">
<?php echo $ten; ?>
</td>
<td width="300px" >
<input style="margin:3px;width:400px" value="<?php echo $gt; ?>" name="<?php echo $name_input; ?>" >
</td>
</tr>
<?php
}
class url_dep
{
function tim_c_127a($c,$tb,$so)
{
$tv="select count(id) from menu where url_dep=’$c’ ";
//die($tv);
$tv_1=mysql_query($tv);
$tv_2=mysql_fetch_row($tv_1);
$atv="select count(id) from dulieu where url_dep=’$c’ ";
//die($tv);
$atv_1=mysql_query($atv);
$atv_2=mysql_fetch_row($atv_1);
$btv="select count(id) from dulieu_1 where url_dep=’$c’ ";
$btv_1=mysql_query($btv);
$btv_2=mysql_fetch_row($btv_1);
$ctv="select count(id) from hop_html where url_dep=’$c’ ";
$ctv_1=mysql_query($ctv);
$ctv_2=mysql_fetch_row($ctv_1);
if($tv_2[0]!=0 and $atv_2[0]!=0 and $btv_2[0]!=0 and $ctv_2[0]!=0 )
{
$so=thong_so_2(25);
$so=$so+1;
up_thong_so_2(25,$so);
$c=$c."-".$so;
return $this->tim_c_127a($c,$tb,$so);
}
else
{
return $c;
}
}
<h5><span style="font-size: 14pt;">noi chuoi</span></h5>
function noi_chuoi_127($ten,$tb)
{
$m=explode(" ",$ten);
$c="";
$so=count($m)-1;
for($i=0;$i<count($m);$i++)
{
if($i!=$so)
{
$c=$c.$m[$i]."-";
}
else
{
$c=$c.$m[$i];
}
}
$c=strtolower($c);
$c=$this->tim_c_127a($c,$tb,"");
return $c;
}
function bo_dau_tieng_viet($str){
$unicode = array(
‘a’=>’á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ’,
‘d’=>’đ’,
‘e’=>’é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ’,
‘i’=>’í|ì|ỉ|ĩ|ị’,
‘o’=>’ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ’,
‘u’=>’ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự’,
‘y’=>’ý|ỳ|ỷ|ỹ|ỵ’,
‘A’=>’Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ’,
‘D’=>’Đ’,
‘E’=>’É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ’,
‘I’=>’Í|Ì|Ỉ|Ĩ|Ị’,
‘O’=>’Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ỗ|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ’,
‘U’=>’Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự’,
‘Y’=>’Ý|Ỳ|Ỷ|Ỹ|Ỵ’,
);
<h6><span style="font-size: 14pt;">bo dau</span></h6>
foreach($unicode as $nonUnicode=>$uni){
$str = preg_replace("/($uni)/i", $nonUnicode, $str);
}
return $str;
}
function bo($c)
{
$c=str_replace(‘"’,”,$c);
$c=str_replace(‘,’,”,$c);
$c_b="`,-,=,\,[,],;,’,.,/,!,@,#,$,%,^,&,*,(,),_,+,|,{,},:,<,>,?";
$m=explode(",",$c_b);
for($i=0;$i<count($m);$i++)
{
$c=str_replace($m[$i],”,$c);
}
return $c;
}
function url_dep($ten)
{
$ten=$this->bo($ten);
//echo $ten."<hr>";
$ten=$this->bo_dau_tieng_viet($ten);
//echo $ten;
$url_dep=$this->noi_chuoi_127($ten);
return $url_dep;
}
}
function noi_dung_cat_ngan($nd,$so)
{
$nd=strip_tags($nd);
$m=explode(" ",$nd);
$c="";
for($i=0;$i<$so;$i++)
{
$c=$c.$m[$i]." ";
}
return $c." …";
}
?>[/sourcecode]
đây là nơi chứa các hàm . Các hàm như cắt ngắn , chuyển tiếng việt …… hàm như nào mình viết rõ rồi nhé
Chúc các bạn học tốt
-
Bạn có thể xem thêm các khóa học ở dưới:
Tag: học thiết kế đồ họa tại hà nội, học thiết kế đồ họa ở hà nội, học thiết kế đồ họa ở đâu, học thiết kế đồ họa ngắn hạn, khóa học thiết kế đồ họa ở hà nội, khóa học thiết kế đồ họa tại hà nội, học thiết kế đồ họa in ấn quảng cáo tại hà nội, khóa học thiết kế đồ họa in ấn quảng cáo tại hà nội, học lập trình web ở đâu, học lập trình web tại hà nội, học lập trình php ở đâu, học lập trình php tại hà nội
- Học thiết kế đồ họa ngắn hạn
- Học lập trình php ở đâu
- Học html css tại hà nội
- Học photoshop tại hà nội
Mọi thông tin bạn có thể liên hệ:
Đào tạo lập trình và thiết kế đồ họa
p.1013 Tòa nhà FLC, 36 Phạm Hùng, Nam Từ Liêm, Hà Nội.(cạnh cổng ra bến xe khách Mỹ Đình)
Hotline: 0968.853.958 hoặc hỗ trợ kỹ thuật Mr. trung: 0947.499.221
Bình luận