Do you need a PHP programmer?
Use my services as a freelance PHP programmer by hiring me to do PHP programming on your website project.

I have built many custom PHP applications like project managers, classified ad websites and content management systems. I also work with open source applications such as WordPress, online shopping cart websites like Magento and develop content management systems like Joomla.

Wednesday, April 18, 2012

Auto Request and Manage Json Data

Hello, ,
Today I have got a new knowledge from programming website.
This is about data-interchange format. Did you ever hear about JSON?

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.( you can read more in www.json.org ).

This is example of json data :

{"name":"bywebs.blogspot.com","time":"12 : 20 : 56"}


And now I will make a tutorial to auto request and manage json data every x seconds. But in this tutorial I will use a jquery script (jquery-1.6.1.min.js).

Let's see for my code :

<script type="text/javascript">

    var auto_refresh = setInterval(function(){ // interval auto refresh
 
        $.getJSON("json.php", function(json) { // request method using jquery

                                               // json.php will return json data

            // parsing data

            var table = '';

            table += '<tr><td>Name</td>';

            table += '<td>'+json['name']+'</td></tr>';

            table += '<tr><td>Server Time</td>';

            table += '<td>'+json['time']+'</td></tr>';

            

            //inser data to Id bywebs

            document.getElementById('bywebs').innerHTML = table;


         });

     }, 5000); // will request json every 5 seconds, you can change it

</script>

You can develop this code by yourself.
so for the complete code you can "Download here".

Hope it useful for all, if you have any question and suggestions, just write your comment below. :)

Good Luck.

Monday, April 16, 2012

Replace space and all Illegal character on string - PHP

Hi, ,
Do you search for how to replace/remove illegal character (@#$%^&* etc) in your text string?
On this post I will share you simple code to make it.
This code will only allowed numbers (0-9) and characters (a-z).

my code :

<?php
    $string = 'by^#^we%%&bs.b_((logs+)&#@pot.()*)(~co!~@#_+m';
    $string = preg_replace('/[^0-9 a-z]+/i', '', $string);
    
    echo $string;
?>

And below is code for replace multiple space on your text string

<?php
    $string = 'by   webs.   blog  spot.  com';
    $string = str_replace(array(' '),array(''),$string);
    
    echo $string;
?>

Hope it will useful for all,
If you have questions or suggestions, please write your comment below.

Good Luck :)

Saturday, April 14, 2012

Make Confirm Dialog Javascript

Hello every body,
When the first time I learned javascript code, I was really happy when I succeed to make pop up dialog, :D
And now I will share a simple code to make a confirmation dialog before you do the actions.
I have some ways, but the simple one is:

<a href="http://bywebs.blogspot.com" onClick="return confirm('Do you realy want to visit my website?');"> My Website </a>

Demo

Beside that I also have the second way, but it will use a function.
Let's take a look

<script type="text/javascript">
    function _confirm(url){
        if(confirm('Do you realy want to show my link?')){
            document.getElementById('myDiv').innerHTML = "<a href='"+url+"'> My Website</a>";
        }
    }
</script>

<a onClick="_confirm('http://bywebs.blogspot.com');">show my link</a>
<div id="myDiv"></div>

Demo
show my link

That's all :).
Hope it will useful, if you have any question , just write your comment below.
Thanks and Good luck

Thursday, April 12, 2012

Cut a string after X characters -- PHP

Hi guys, ,
In this my post, let's we talk about string manipulation using PHP code.
There are many functions of php that you can use to manipulation your string.
But now I will share you a simple way how to cut a string after x characters.
We will use 2 manipulation functions of php, they are strlen ( for count characters of your string ) and substr ( for cut characters of your string ).

This is my code :

<?php  
    if(isset($_POST['submit'])){          
            
            $text = $_POST['text'];
            
            //check if you have value in text.  
            if(empty($text)){  
               echo "<h3>Error: Please complete the form.<a href=\"$_SERVER[PHP_SELF]\">back</a></h3>";  
               exit(); //exit the script and don't process the rest of it!  
            }  
            
            $limit = 10; //limit the char will cut
            if (strlen($text) > $limit) {
                $text = substr($text, 0, $limit) . '...'; //if $text more than $limit char will replace with (...)
            } else {
                $text = $text;
            }
                   
            //success message, redirect to main page.          
            $msg = urlencode("Result of your string : <h4>$text</h4> <a href=\"cut_string.php\">Try again?</a>");  
                header("Location: cut_string.php?msg=$msg");  
                exit();  
              
          
    }else{  
            //if there is a message, display it  
            if(isset($_GET['msg']))  
            {  
                //but decode it first!  
    
                echo "<p>".urldecode($_GET['msg'])."</p>";  
            }  
            //the upload form  
        echo "  
        <h1>Simple code to cut a string after X characters PHP - <a href=\"http://bywebs.blogspot.com\">bywebs.blogspot.com</a></h1>
        <form action=\"$_SERVER[PHP_SELF]\" method=\"post\"enctype=\"multipart/form-data\">\n  
        <p>Your text:<input type=\"text\" name=\"text\" /></p>\n  
        <p><input type=\"submit\" name=\"submit\" value=\"Submit\" /></p>";  
    }  
?>

Just a simple code :)
Let's try for your self, for the complete file you can "Download Here".
Hope it useful for all, if you have any question, you can write your comment below :)

Good Luck :)

Simple Upload and Resize Image using php

According to my post title above, now I will share a simple code about make upload and resize image using php. Exactly the code I got from searching on google, but I have made a little modification so now the code become a bit nicer than before. hehe ;).

 Let's take look for my code:

 Resize.php

<?php

if(isset($_POST['submit']))
    {        
        //directory destination , make sure this directory is writable!
        $path_thumbs = "C:\\bayu";
        $path_big = "C:\\bayu\\thumb";
        
        //the new width of the resized image, in pixels.
        $img_thumb_width = 100; // 

        $extlimit = "yes"; //Limit allowed extensions? (no for all extensions allowed)
        //List of allowed extensions if extlimit = yes
        $limitedext = array(".gif",".jpg",".png",".jpeg",".bmp");
        
        //the image -> variables
        $file_type = $_FILES['vImage']['type'];
        $file_name = $_FILES['vImage']['name'];
        $file_size = $_FILES['vImage']['size'];
        $file_tmp = $_FILES['vImage']['tmp_name'];

        //check if you have selected a file.
        if(!is_uploaded_file($file_tmp)){
           echo "Error: Please select a file to upload!. <br>--<a href=\"$_SERVER[PHP_SELF]\">back</a>";
           exit(); //exit the script and don't process the rest of it!
        }
       //check the file's extension
       $ext = strrchr($file_name,'.');
       $ext = strtolower($ext);
       //the file extension is not allowed!
       if (($extlimit == "yes") && (!in_array($ext,$limitedext))) {
          echo "Wrong file extension.  <br>--<a href=\"$_SERVER[PHP_SELF]\">back</a>";
          exit();
       }
       //so, whats the file's extension?
       $getExt = explode ('.', $file_name);
       $file_ext = $getExt[count($getExt)-1];

       //create a random file name
       $rand_name = md5(time());
       $rand_name= rand(0,999999999);
       //the new width variable
       $ThumbWidth = $img_thumb_width;

       //////////////////////////
       // CREATE THE THUMBNAIL //
       //////////////////////////
       
       //keep image type
       if($file_size){
          if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){
               $new_img = imagecreatefromjpeg($file_tmp);
           }elseif($file_type == "image/x-png" || $file_type == "image/png"){
               $new_img = imagecreatefrompng($file_tmp);
           }elseif($file_type == "image/gif"){
               $new_img = imagecreatefromgif($file_tmp);
           }
           //list the width and height and keep the height ratio.
           list($width, $height) = getimagesize($file_tmp);
           //calculate the image ratio
           $imgratio=$width/$height;
           if ($imgratio>1){
              $newwidth = $ThumbWidth;
              $newheight = $ThumbWidth/$imgratio;
           }else{
                 $newheight = $ThumbWidth;
                 $newwidth = $ThumbWidth*$imgratio;
           }
           //function for resize image.
           if (function_exists(imagecreatetruecolor)){
           $resized_img = imagecreatetruecolor($newwidth,$newheight);
           }else{
                 die("Error: Please make sure you have GD library ver 2+");
           }
           //the resizing is going on here!
           imagecopyresized($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
           //finally, save the image
           imagejpeg ($resized_img,"$path_thumbs/$rand_name.$file_ext");
           imagedestroy ($resized_img);
           imagedestroy ($new_img);
           
           
        }

        //ok copy the finished file to the thumbnail directory
        move_uploaded_file ($file_tmp, "$path_big/$rand_name.$file_ext");
             
        //success message, redirect to main page.        
        $msg = urlencode("$title was uploaded! <a href=\"Resize.php\">Upload More?</a>");
            header("Location: Resize.php?msg=$msg");
            exit();
        
    
}else{
        //if there is a message, display it
        if(isset($_GET['msg']))
        {
            //but decode it first!
            echo "<p>".urldecode($_GET['msg'])."</p>";
        }
        //the upload form
    echo "
    <form action=\"$_SERVER[PHP_SELF]\" method=\"post\"enctype=\"multipart/form-data\">\n
    <p>File:<input type=\"file\" name=\"vImage\" /></p>\n
    <p><input type=\"submit\" name=\"submit\" value=\"Submit\" /></p>";
}

?> 

Upss, ,  it's long enough, but never mind because I'm sure the code will work as well.
Notice : make sure the directory destination , is writable!
       $path_thumbs = "C:\\bayu";
       $path_big = "C:\\bayu\\thumb";

or you can change it as you want. :)
for the complete file you can "Download here"
Okay, that's all.!!
if you have any question just write your comment below :)

Good Luck!!


Tuesday, April 10, 2012

Slide up down (Toggle Slide) using jquery

Hello everybody,
Now I will share how to make slide up and down (toggle slide) using jquery.
And this is for the demo, check it out :


- Category
List Category 1
List Category 2
List Category 3

Ok, Let's take look for the code:

    I just use a jquery script (jquery-1.6.1.min.js) and a simple script to call toggle jquery

<script type="text/javascript" src="jquery-1.6.1.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
         //$(".block-t-content").hide(); just active this if u want hide for default
         $("#bywebs").click(function(){
            $(this).toggleClass("active").next().slideToggle("slow");
            return false;
        });
    });
</script>


    This is my css code:

<style type="text/css">
#content {
    border:1px solid #c5c5c5;
    width:200px;
    margin:0px 5px;
    border-radius:4px;
}
#main {
    background:#c5c5c5;    
}
</style>


And the last is my html code :

<div id="content">       
    <div id="bywebs">
        <div id="main">- Category</div>
    </div>
    <div class="block-t-content">
        <div class="block">
            <div>List Category 1</div>
            <div>List Category 2</div>
            <div>List Category 3</div>
        </div>
    </div>
</div>


Finished!!That's all.
For the complete file, you can download in this link 'Download Toggle slide'
Hope it useful for all, if you have any question, you can write your comment below :)

Good Luck :)


Sunday, April 8, 2012

Add and Remove table row (javascript).

Hi everyone,
Now I will share a simple script how to Add and Remove table row by javascript.
exactly it was my problem before, it made me very confused because sometime when it work, it removed wrong row, so oh god . . .
But now I have fixed it.

I have a table with some task,


When we click delete button, it will delete the right row and if we click add button it will automatically add new row on the last of table.
Look for the script below :

#javascript

<script type="text/javascript">
    function remove(id){
        // initial variable
        var table = document.getElementById('schedule'); // get table id
        var rows = table.getElementsByTagName('tr'); // get all table rows
        var target = id; // row will remove
        var j = 1;
        
        for(i=0;i<rows.length;i++,j++){
            if(rows[i].id==target){
                table.deleteRow(i); 
                i--;
            }else{
                j--;
            }
        }
    }
    
    function add(){
        var table = document.getElementById('schedule'); // get table id
        var lastRow = table.getElementsByTagName('tr').length; // get last row
        var newId = lastRow+1; // make new id
        
        var row = document.getElementById('schedule').insertRow(lastRow); // create row
        row.setAttribute('id','task'+newId); // insert row id
        
        var cell0 = row.insertCell(0);// create cell 1
        var cell1 = row.insertCell(1);// create cell 2
        cell0.innerHTML = 'Task '+newId+' - Default'; // insert data cell 1
        cell1.innerHTML = '<a style="cursor:pointer;" onClick="remove(\'task'+newId+'\');" >X</a>';// insert data cell 2
    }
</script>

#HTML script

<table cellpadding="0" cellspacing="0" width="300" border="1" id="schedule">
<?php
 for($i=1; $i<5; $i++){
?>
  <tr id="task<?php echo $i; ?>">
            <td>Task <?php echo $i; ?> - Default</td>
            <td><a style="cursor:pointer;" onClick="remove('task<?php echo $i; ?>');" >X</a></td>
        </tr>
<?php
 }
?>
</table>
<input type="button" onClick="add();" value="add" /> 


Hope it useful for all, if you have question, just write your comment below.

Good luck :)

Thursday, April 5, 2012

Build New Category Widget for Your Website

Hallo , ,
Come back again,
On this post, I still share about how to make your website ( blogspot) look nicer.

Now we will build a new widget to grouping all of your article based on their categories.
Categories widget is very important thing for your website, otherwise it will group all of your article based on their categories, it also will make your visitors become easy when they read or just look for your articles.
So surely your website will look nicer and professional.

I have simple way to build it by using standard additional widget from blogspot platform
Ok, let's see how we will make it.
  1. Login to your website account
  2. Choose "Layout" on your menu
  3. Then choose "Add a Gadget" on your sidebar layout, it will show a pop up window with many gadget choices. On this part you should choose "Label" gadget. And new window will display an image below.

         Change the title become "Categories". yupss, finished.
         You can push Save button now.

Note : Categories widget will group your articles based on their labels, so don't forget to put labels when you create a new post for your website.

Hope it useful for all, Thank you :)

Hide Navbar Blogger by Using Simple CSS

When I built this website, I just used one of free template ( awesome inc template ) from Blogspot Platform and  its design was very simple. But I thought I should do some things to make it better and look nicer. Then I tried to make it different by hide navbar on header of my website.

How did I make it?

I just used simple way by added some css script,
let's look for the script :

/*  hide navbar header  */

#navbar-iframe {display:none;}

You can copy and paste the script above to your template.
I will point you how to use it,

  1. The first one you should login to your blogspot account.
  2. Click "Template" on menu
  3. Click "Edit Html" and then chose "Process"
  4. To make it easier, push ctrl + f button on keyboard and search for this script "]]></b:skin> ".
  5. Copy my script above and paste before  "]]></b:skin> " script.
  6. Ok, you can save your template now.


I think it enough, let's see how does your site look like !!
But if you still confused or need help or ask for something else,
don't hesitate to comment here,
if I know I will shared.


Good Luck :D

What is PTC ( Paid To Click )?

Paid To Click is an online business program. Paid To Click or simply PTC websites provides an easy way to earn money online. PTC just middlemen between advertisers and consumers.
Advertiser   ->   PTC website  ->  Member

Advertiser will pay to PTC website for every ads that displayed.
PTC website will display all of ads from advertiser.
Member will get paid from PTC website if they make click and display the ads that given by PTC website.

I have tried this program and I have felt so nice because while I do my homework or something in the front of my computer, I also can make money. Though it is not too much but it is so meaningful.

I have joined in any PTC website (Neobux.com).
I get 6 till 10 ads for everyday.
for click 1 ads, I will get paid $0,001.
so for click 10 ads I will get paid $0,010.
Then I want to learn, How can I get more?

I have the way.
If I want have more income, I should have many refferal.
Refferal is a person that joins a PTC website through your referral link.
Every click from your refferal, you will get paid $0,001.
so for example if you have 10 refferal and make click 10 ads everyday, you will get paid $0,001 x 10 x 10 = $0,1 / day = $0,1 x 30 = $3 / month.

Now you can imagine if you have refferal 100, 1000 or more.
you will get much additional income by click some ads and it doesn’t spend your time more then 15 minutes.

You can try it by click banner below :