Wednesday 29 October 2014

Show First 3/n Words From A String Value In PHP

Below code will explain how to do this in detail.

<?php

function showStripString ($num,$myString,$maxNumOfWords) {
    if($num>0) {
        if($num<=$maxNumOfWords) {
            $spaceChar = '/\S*';
            for($i=1;$i<$num;$i++) {
                $spaceChar .= '\s\S*';
            }
            $spaceChar .='/';
            preg_match("$spaceChar", $myString, $result);
            return $result[0];
        }else return "ERROR !!! Number of words exceeded the actaul number of words in you string ($myString)";
    }   
    else return "ERROR !!";
   
}
//your string
$str = "i want to buy a new car";
//Number of words you want to show
$number=3;

//remove whitespace from beginning and end of string
$str = trim($str);
//get number of whitespace
$nuberOfWhiteSpace = substr_count($str, ' ');
//Get Total number of words
$TotalNumberOfWords = $nuberOfWhiteSpace + 1;

//call function
echo showStripString(intval($number),$str,$TotalNumberOfWords);

?>

Wednesday 30 July 2014

Font with Icons (Font-Awesome)



Hai Developers, here I introduce a website for Awesome Font. They provide lot of icons in their font elements. So we need not add images for icons, just use their fonts. It is very easy and simple. So our web page will load very fast. Please check the below link.


 

WAMP Server Offline Error


One day, when I was run my WAMP server, it goes to offline. I checked is there any applications (Skype, Antivirus etc.) are running simultaneously. Everything was okay, but WAMP still shows offline. Finally I found the reason. It is because of; I changed my local IP address previous day, which is also used in apache config file for LAN WAMP connection. I commented the line as shown below in apache httpd.conf file.

#Listen 192.168.1.22:8081 

After that I restarted my WAMP server and it goes to online. :)

Thursday 15 May 2014

Solve: The Program Can't Start Because MSVCR100.dll is missing from your computer

When I was installing WAMP server on my formatted PC, I get this error.This issue because of, I didn't install any Microsoft Visual C++. The MSVCR100.dll file is part of the Microsoft Visual C++. You need to install this dll.

 For Windows 32 bit OS:

Microsoft Visual C++ 2008 SP1 Redistributable Package (x86)

Microsoft Visual C++ 2010 SP1 Redistributable Package (x86)

 

 For Windows 64 bit OS:
 
Microsoft Visual C++ 2008 Redistributable Package (x64)

Microsoft Visual C++ 2010 SP1 Redistributable Package (x64)



 For Windows 8:

Check this link Click  

Tuesday 18 March 2014

Pass Values Using Anchor Tag

Methode: 1


<a href="urlink.php?myvalueone=1&myvaluetwo=2">Pass Values</a>


In urlink.php

<?php   

    echo $_REQUEST["myvalueone"];
    // OR
    echo $_GET["myvalueone"];

    //AND

    echo $_REQUEST["myvaluetwo"];
    //OR
    echo $_GET["myvaluetwo"];

    //Process your actions here
   
?>

Result: 1122



Methode: 2

 

<form action="urlink.php" method="POST">

<input type="hidden" name="myvalueone" value="1" />
<input type="hidden" name="myvaluetwo" value="2" />

<a href="#" onclick="this.parentNode.submit()">Pass Values</a>

</form>


In urlink.php

<?php
       
    echo $_REQUEST["myvalueone"];
    // OR
    echo $_POST["myvalueone"];

    //AND

    echo $_REQUEST["myvaluetwo"];
    //OR
    echo $_POST["myvaluetwo"];
   
    //Process your actions here

?>

Result: 1122



Methode: 3


<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.0.min.js"></script>

<a href="#NOD" rel="2" id="myvalues">Pass Value</a>

<script type="text/javascript">

    $(document).ready(function() {
        $('#myvalues').click(function() {
            $.ajax({
                type: "POST",
                url: "urlink.php",
                data:  {'myvalue' : $(this).attr('rel')},
                success: function(data) {
                alert(data);
                }
            });
    });
    });

</script>


In urlink.php

 
<?php
    //Process your actions here
    echo $_POST['myvalue'];
?>

Result:Javascript alert, popup with value 2

Monday 3 February 2014

Wamp Error: cannot execute menu item internal error

When I install wamp server on my friend's PC I got error like "Could not execute menu item (internal error)[Exception]".I goggled with this error and got solution.


Solution:1

please make sure none of following services is running on your system.
IIS, Skype, Zone Alarm, NOD32, Eset, Internet Optimizer, Google Accelerator, any other database server, any other webserver?
If you using any of the above application close it and select “restart all services” from WAMP menu.


Solution: 2

By default , the WAMP server will take 80 as its working port.You can change that port number as you like ... here are the steps to do that:
  •     click on WAMP server tray icon
  •     click on apache
  •     select http.conf(Here notepad will open ...).
    Scroll down and you will see the port number that WAMP server takes, change that port number to:

                                                     #Listen 12.34.56.78:80
                                                      Listen 80
    
                                                                      TO

                                                     #Listen 12.34.56.78:80
                                                      Listen 8080


    Save that file and restart the services. It will work fine. Now check by typing http://localhost:8080/.

Tuesday 28 January 2014

Custom AJAX File Uploader

I am very happy to share custom AJAX file up loader. It is very simple and using basic codes. So you can easily understand my code.

How to integrate this code ?


1. First you create index file, index.php


<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
<form id="myUploadForm" name="myUploadForm" action="" method="post" enctype="multipart/form-data">
<input type="file" name="file[]" id="fileUpload" multiple="multiple" />
<input type="hidden" name="uploadedFilename" id="uploadedFilename" value="" />
</form>
<ul id="filelist">

</ul>
<script type="text/javascript">
$(function() {

    $(".removeUploadedFile").live('click',function() {
        var sel = $(this);
        if(!confirm("Do you want to remove this file ?")) return false;
        $.post('request.php',{action: 'remove', file: sel.attr('rel')}, function(data){
            if(data>0) {
                sel.closest('li').remove();
            }
        });
    });


    $("#fileUpload").change(function (e) {
            var sel = $(this);
            $.map($('#fileUpload').get(0).files, function(file) {
                $("#uploadedFilename").val(file.name);
                     e.preventDefault();
                    var formData = new FormData(sel.parents('form')[0]);
           
                    $.ajax({
                        url: 'request.php',
                        type: 'POST',
                        xhr: function() {
                            var myXhr = $.ajaxSettings.xhr();
                            return myXhr;
                        },
                        success: function (data) {
                            $("#filelist").append(data);
                            $("#fileUpload").val('');
                        },
                        data: formData,
                        cache: false,
                        contentType: false,
                        processData: false
                    });
                    return false;
            }); 
     });
});
</script>


2. Create another file request.php for AJAX call, request.php


<?php

switch ($_REQUEST['action']) {

        case 'upload':
        $targetPath = "uploads/";
        for($i=0; $i<count($_FILES['file']['name']); $i++){
               
                $tempFile =   $_FILES['file']['name'][$i];
                if($tempFile == $_REQUEST['uploadedFilename']){
                    //$targetFile =  str_replace('//','/', $targetPath) . $newFileName;
                    $cpy=0;
                    do {
                       
                        if($cpy>0)
                        $fileName="Copy".$cpy.$tempFile;
                        else $fileName=$tempFile;
                        $targetFile =  str_replace('//','/',$targetPath) .$fileName;
                        $cpy++;
                    }while(is_file($targetFile));
                       
                    if(move_uploaded_file($_FILES['file']['tmp_name'][$i], $targetFile)) {
                        echo "<li>".$fileName."&nbsp;&nbsp;<a href='#NOD' class='removeUploadedFile' rel='".$fileName."'>Remove</a><input type='hidden' name='hdnAttach[]' value='".$fileName."' ></li>";
                    } else{
                        echo "<li>There was an error uploading the file(".$fileName."), please try again! </li>";
                    }
                   
                }
               
        }
        break;
       
        case 'remove':
            if(file_exists("uploads/".$_POST['file'])) {
                unlink("uploads/".$_POST['file']);
                    echo 1;
                }
        break;

}

?>

3. Create a folder 'uploads' for upload image.The uploaded image should be stored in this folder.

 

 

Root Path :