[trick] beberapa plugin php yang dipakai untuk edit photo


// IMG_FILTER_EDGEDETECT
// IMG_FILTER_BRIGHTNESS
// IMG_FILTER_COLORIZE
// IMG_FILTER_EMBOSS
// IMG_FILTER_GAUSSIAN_BLUR
// IMG_FILTER_GRAYSCALE
// IMG_FILTER_NEGATE
// IMG_FILTER_MEAN_REMOVAL
// IMG_FILTER_SMOOTH

header("Content-type:image/jpeg");
$image = imagecreatefromjpeg('koala.jpg');
imagefilter($image,IMG_FILTER_GRAYSCALE,70);
imagejpeg($image);

kali ini saya akan menggunakan gray scale, yang hasilnyan seperti ini.

koala

 

fungsi lainnya :

https://topidesta.wordpress.com/2015/04/08/memaksimalkan-penggunaan-input-typerange-html-5/

Share Custom Share Social Media

like and share

kita pasti mikir gimana ya caranya button share atau like itu kita buat sendiri , bukan memakai langsung dari facebook atau sosmed lainnya.

nah saya share share dikit aja disini, ya meskipun sedikit mudah2an membantu lah.. hahaha

untuk facebook:

</pre>
<a href="https://www.facebook.com/sharer/sharer.php?u=<? echo $url_webnya ;?>">share fb</a>

untuk twitter:

</pre>
<a href="https://twitter.com/intent/tweet?text=<?php echo $title_web; ?> <?=$url_webnya;?>">share twiiter</a>

untuk google_plus:

</pre>
<a href="https://plus.google.com/share?url=<?php echo $url; ">share g+</a>

Nah demikian lah scriptnya, mudah bukan. heheh, selamat mencoba

CRUD PHP dan XML 2.0

> View.php


<?php
require('simplexml.class.php');
//delete
if($_GET['act']=='hapus'){
$product = simplexml_load_file('product.xml');
$id = $_GET['id'];
$index = 0;
$i= 0;
foreach($product->product as $produk){
if($produk->id_produk == $id){
$index = $i;
break;
}
$i++;
}
unset($product->product[$index]);
file_put_contents('product.xml',$product->asXml());

}
//end of delete

$product = simplexml_load_file('product.xml');
$json = json_encode($product);
$array = json_decode($json,TRUE);
$jumlah = count($array);
$no=1;
echo"<a href='add.php'> <button>add</button> </a> <br><br>";
echo "<table border=0 width=100% style='padding:15px; border:1px solid #000;'> ";
echo "<tr bgcolor='#ccc'> <td>No</td> <td>Nama</td> <td>Harga</td> <td>Edit</td> <td>Hapus</td></tr> ";
foreach($product->product as $produk ){
if(($no%2)==0){
$warna="#ccc";
}else{
$warna="#fff";
}
echo "<tr bgcolor='$warna'><td>".$no."</td>";
echo "<td>".$produk->name."</td>";
echo "<td>".$produk->price."</td>";
echo "<td><a href='edit.php?id=".$produk->id_produk."'> <button>Edit</button></a></td>";
echo "<td><a href='index.php?act=hapus&id=".$produk->id_produk."'><button>Delete</button></a></td></tr>";
$no++;
}
echo" </table>";
?>

> add.php


<?php
if($_POST['save']){
require('simplexml.class.php');
$products = simplexml_load_file('product.xml');
$product = $products->addChild('product');
$product->addChild('id_produk',$_POST['id_produk']);
$product->addChild('name',$_POST['name']);
$product->addChild('price',$_POST['price']);
file_put_contents('product.xml',$products->asXml());
header('location:index.php');
}
?>
<form method="POST">
<p> ID <input type="text" name="id_produk"></p>
<p> Nama <input type="text" name="name"></p>
<p> Harga <input type="text" name="price"></p>
<input type="submit" value="Simpan" name="save"></p>
</form>

> Edit.php


<?php
require('simplexml.class.php');
$products = simplexml_load_file('product.xml');
if($_POST['save']){

foreach($products->product as $product){
if($product->id_produk == $_POST['id_produk']){
$product->name = $_POST['name'];
$product->price = $_POST['price'];
break;
}
}
file_put_contents('product.xml',$products->asXml());
header('location:index.php');
}
foreach($products->product as $product){
if($product->id_produk == $_GET['id']){
$id = $product->id_produk;
$name = $product->name;
$price = $product->price;
break;
}

}
?>
<form method="POST">
<p> ID <input type="text" name="id_produk" value="<?php echo $id; ?>" readonly="readonly"> </p>
<p> Nama <input type="text" name="name" value="<?php echo $name; ?>"></p>
<p> Harga <input type="text" name="price" value="<?php echo $price; ?>"></p>
<input type="submit" value="Simpan" name="save"></p>
</form>

>product.xml

<?xml version="2.0" encoding="utf-8"?>
<products>
 <product>
 <id_produk> 1 </id_produk>
 <name> Gula </name>
 <price>200000</price>
 </product>
 <product>
 <id_produk>2</id_produk>
 <name>minyak</name>
 <price>10000</price>
 </product>

<product><id_produk>3</id_produk><name>sabun</name><price>10000</price></product><product><id_produk>4</id_produk><name>mie instant</name><price>45789</price></product></products>

> Hasil

xml

Contoh Array Dua Dimensi Php dengan Data Static dan Dinamic

sudah lama ng ngepos lagi disini, dan kali ini ada kesempatan buat ngepos mskipun sedikit waktunya.

kali ini saya ngebahas array dua dimensi yang static dan dinamic

> static


<?php
$fruits = array ( "fruits" => array ( 1 => "orange",
2 => "banana",
3 => "apple"
),
"numbers" => array ( 1 => "orange",
2 => "banana",
3 => "apple"
),
"holes" => array ( 1 => "orange",
2 => "banana",
3 => "apple" )
);

echo"<ul>";
foreach($fruits as $index => $buah){
echo "<li>".$index."<ul>" ;
for($i=1;$i<=count($buah);$i++){
echo "<li>".$buah[$i]."</li>";
}
echo"</ul></li>";
}
echo"</ul>";
?>

///////////////////////////////////////////////////////////////////////////////////////////////////////////

> dinamic

teset


<?php
mysql_connect("localhost","root","12345");
mysql_select_db("belajar");
echo"<ul>";
$sql= mysql_query("SELECT DISTINCT parent_id, GROUP_CONCAT( DISTINCT child_id
ORDER BY child_id ) AS child_id_list
FROM table_anda
GROUP BY parent_id");

while($data=mysql_fetch_array($sql)){

echo "<li>".$data['parent_id']."<ul>" ;
for($i=1;$i<=count($data['child_id_list']);$i++){
echo "<li>".$data['parent_id'][$i].$data['child_id_list']."</li>";
}
echo"</ul></li>";
}
echo"</ul>";
?>

Hasilnya :

teset

jangan salah lo , diluar sana byk prgrammer yang masih lemah dalam array lo, hehehe

Algoritma Boyer More Dengan PHP MYSQL

Sekarang Mungkin Post Postan nya sedikit beda. hehe. karna ane lagi ngalamin kasus tersebut skrng..

dan sekalian ane share share siapa tau ada yang berminat hehehe.. oke lansung saja..

> database :

database

> Code

form.php


<h3>Pasal/Perkara</h3>
Ini adalah pasal/perkara.<br> <hr>
<form method='post' action='cari_pasalperkara.php'>
<table border='0' cellpadding='4' cellspacing='0'>
<tr><td colspan=2><b>Cari Pasal / Perkara<b></td><tr>
<tr><td>Pasal</td> <td> <input type='search' name='cari' placeholder='Masukkan Pasal/Perkara' size=35> </td></tr>
<tr><td></td><td><input type='submit' value='Cari Pasal'></td></tr>
</table>
</form>

cari_pasalperkara.php


<?php
include"admin/koneksi.php";
echo"
<h3>Pasal/Perkara:</h3><br>
";

$pattern = $_POST['cari'];
$sqlQuery=mysql_query("select * from pasal where isi LIKE '%$pattern%'");
$ketemu = false;
$text[] = array();
$arrayOutput[] = array();
$x = 0;
$y = 0;
while($data=mysql_fetch_array($sqlQuery)){
$text[$x] = $data;
$x++;
}

$jumlah = count($text);
echo "Jumlah = ",$jumlah;
for($p=0; $p<$jumlah; $p++){
$hasil = BoyerMoore($text[$p]['isi'], $pattern);
if($hasil != -1){
$ketemu = true;
$arrayOutput[$y] = $text[$p];
$y++;
}
}

if($ketemu == true){
echo "<br><br>KETEMU";
$jumlahKetemu = count($arrayOutput);
echo "<br>Jumlah Ketemu = ",$jumlahKetemu;
echo "<br><br>HASIL:";
for($q=0; $q<$jumlahKetemu;$q++){
echo "<br>Nama Pasal = ",$arrayOutput[$q]['nama_pasal'];
echo "<br>Ayat = ",$arrayOutput[$q]['ayat'];
echo "<br>Isi = ",$arrayOutput[$q]['isi'];
}
}
else {
echo "<br><br>Tidak Ditemukan";
}
/**
* Returns the index of the first occurrence of the
* specified substring. If it's not found return -1.
*
* @param text The string to be scanned
* @param pattern The target string to search
* @return The start index of the substring
*/
function BoyerMoore($text, $pattern) {
$patlen = strlen($pattern);
$textlen = strlen($text);
$table = makeCharTable($pattern);
for ($i=$patlen-1; $i < $textlen;) {
$t = $i;
for ($j=$patlen-1; $pattern[$j]==$text[$i]; $j--, $i--) {
if($j == 0) return $i;
}
$i = $t;
if(array_key_exists($text[$i], $table))
$i = $i + max($table[$text[$i]], 1);
else
$i += $patlen;
}
return -1;
}
function makeCharTable($string) {
$len = strlen($string);
$table = array();
for ($k=0; $k < $len; $k++) {
$table[$string[$k]] = $len - $k - 1;
}
return $table;
}


echo"
<p><a href='javascript:history.go(-1)'> <input type='button' value='Kembali'> </a>
";
?>

>Hasilnya

hasil

[trick] Pop Up Window Advance Dengan PHP Dan Javascript

database

Koneksi.php


$server = "localhost";
$username = "root";
$password = "12345";
$database = "buku";

mysql_connect($server,$username,$password) or die("Koneksi gagal");
mysql_select_db($database) or die("Database tidak bisa dibuka");

?

Searchpopup.php


<?php
echo"<form id='form' name='form' method='post' action=''>
 <table width='314' border='0' cellspacing='0' cellpadding='0'>
 <tr>
 <td width='80'>Nama</td>
 <td width='368'>
 <input type='text' name='nama'/>
 <input name='cari2' type='button' id='cari2' onclick=window.open 
('popupsearch.php','','height=200,width=480,scrollbars=yes') value='Search' 
/>
 </td>
 </tr>
 <tr>
 <td>Alamat</td>
 <td><input type='text' name='alamat' /></td>
 </tr>
 <tr>
 <td>Tlp</td>
 <td><input type='text' name='tlp' /></td>
 </tr>
 </table>
</form>";
?>


popsearch.php


<style type="text/css">
<!--
.head_tbl {
font-size: 14px;
font-weight: bold;
font-family:Verdana, Arial, Helvetica, sans-serif;
text-transform: uppercase;
color: #FFFFFF;
background-color: #006699;
}

.style9 { color: #000000;
font-size: 9pt;
font-weight: normal;
font-family: Arial;
}
-->
</style>
<script type="text/javascript">
function ambil(a){
window.opener.document.form.nama.value = document.getElementById("nama"+a+"").innerHTML;
window.opener.document.form.alamat.value = document.getElementById("alamat"+a+"").innerHTML;
window.opener.document.form.tlp.value = document.getElementById("tlp"+a+"").innerHTML;
window.close();

}

</script>
<table width="100%" border="0">
<tr>
<td><form id="form" name="form1" method="post" action="">
<label>
Nama
<input type="text" name="cari" id="cari" />
</label>
<label>
<input type="submit" name="button" id="button" value="cari" onClick="pencarian()" />
</label>
</form></td>
</tr>
</table>
<table width="458" border="1">
<tr class="head_tbl">
<td width="122" bgcolor="#006699"><div align="center">Nama</div></td>
<td width="224" bgcolor="#006699"><div align="center">Alamat</div></td>
<td width="90" bgcolor="#006699"><div align="center"><span class="style1">Tlp</span></div></td>
</tr>
<?php
error_reporting(0);
include"koneksi.php";
$hal = $_GET[hal];
if(!isset($_GET['hal'])){
$page = 1;
} else {
$page = $_GET['hal'];
}
$jmlperhalaman = 20; // jumlah record per halaman
$offset = (($page * $jmlperhalaman) - $jmlperhalaman);
if($_GET['flag']==1)
{
$cari=$_GET['cari'];
$sql=mysql_query("select * from pelanggan where nama LIKE '%".$cari."%' limit $offset, $jmlperhalaman") or die (mysql_error());

}
else
{

$sql=mysql_query("select * from pelanggan limit $offset, $jmlperhalaman") or die (mysql_error());
}
$i=1;
while($rs=mysql_fetch_array($sql))
{
if($i%2==0)
{
echo("<tr onclick=\"ambil('$rs[0]')\" bgcolor=\"#FFEEEE\">");
}
else
{
echo("<tr onclick=\"ambil('$rs[0]')\">");
}?>
<td width="122" id="nama<?=$rs[0];?>"><?=$rs[nama];?></td>
<td width="224" id="alamat<?=$rs[0];?>"><?=$rs[alamat];?></td>
<td width="90" id="tlp<?=$rs[0];?>"><?=$rs[tlp];?></td>
<? $i++;
}
?>
</table>
<?

if($_GET['flag']==1)
{
$cari=$_GET['cari'];
$total_record = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM pelanggan where nama LIKE '%".$cari."%'"),0);
}
else
{
$total_record = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM pelanggan"),0);
}
$total_halaman = ceil($total_record / $jmlperhalaman);
echo "<center>";
$perhal=4;
if($hal > 1){
$prev = ($page - 1);
if($_GET['flag']==1)
{
echo "<a href=$_SERVER[PHP_SELF]?hal=$prev&cari=$_GET[cari]&flag=1> << </a> ";
}
else
{
echo "<a href=$_SERVER[PHP_SELF]?hal=$prev> << </a> ";
}
}
if($total_halaman<=10){
$hal1=1;
$hal2=$total_halaman;
}else{
$hal1=$hal-$perhal;
$hal2=$hal+$perhal;
}
if($hal<=5){
$hal1=1;
}
if($hal<$total_halaman){
$hal2=$hal+$perhal;
}else{
$hal2=$hal;
}
for($i = $hal1; $i <= $hal2; $i++){
if(($hal) == $i){
echo "[<b>$i</b>] ";
} else {
if($i<=$total_halaman){
if($_GET['flag']==1)
{
echo "<a href=$_SERVER[PHP_SELF]?hal=$i&cari=$_GET[cari]&flag=1>$i</a> ";
}
else
{
echo "<a href=$_SERVER[PHP_SELF]?hal=$i>$i</a> ";
}
}
}
}
if($hal < $total_halaman){
$next = ($page + 1);
if($_GET['flag']==1)
{
echo "<a href=$_SERVER[PHP_SELF]?hal=$next&cari=$_GET[cari]&flag=1> >> </a>";
}
else
{
echo "<a href=$_SERVER[PHP_SELF]?hal=$next> >> </a>";
}
}
echo "</center>";
?>
<script type="text/javascript">
function pencarian()
{
var cari=document.getElementById('cari').value;
document.form1.action="popupsearch.php?flag=1&cari="+cari;
document.form1.submit();
}
</script>

hasil_akhir