How to remove WordPress admin bar

WordPress is the powerful CMS. WordPress provide awesome functionality to the admin bar. Using admin bar we can quickly access some admin feature form the front side of the WordPress. But many times we don’t want to display its front side. So let’s see how to remove WordPress admin bar.

Continue reading How to remove WordPress admin bar

How to remove duplicate value from the array using PHP?

Many time we get the array with contains the duplicate value. how we can find that duplicate value form array and remove it easily. we can remove duplicate value from the array using array_unique() function of PHP. Let’s the example If our array look like.

Continue reading How to remove duplicate value from the array using PHP?

How to remove untracked files from current branch GIT?

How to remove untracked files from current branch GIT. many times we need to face that when we run command “git status” at that time git show you untracked files or folder.

How we can remove that untracked files and folder from local git using the command.

Continue reading How to remove untracked files from current branch GIT?

PHP remove non-empty directory using Window Command.

PHP remove non-empty directory using exec windows command. On window operating system when we try to remove non-empty directory every time we get the “directory is not empty.” message when we try to remove directory using PHP.

Let’s see how we can remove non-empty directory using exec window command.

exec(‘attrib -r -a -s -h folderpath /s /d’);
exec(‘rd /s /q folderpath’);

Using above exec command we can remove the non-empty directory.

If you face any issue after using this code please write comment below.

PHP remove non empty directory

How to remove directory using PHP. We can remove directory using rmdir funciton on PHP. But when we can try to remove non-empty directory using “rmdir” function we got exception/error something like “The directory is not empty.”.

So let’s see how we can remove non-empty directory using PHP. For remove non-empty directory using below function.

function deleteDirectory($dir) {
    if (!file_exists($dir)) {
        return true;
    }

    if (!is_dir($dir)) {
        return unlink($dir);
    }

    foreach (scandir($dir) as $item) {
        if ($item == '.' || $item == '..') {
            continue;
        }

        if (!deleteDirectory($dir . DIRECTORY_SEPARATOR . $item)) {
            return false;
        }

    }

    return rmdir($dir);
}

you can used above function for remove non-empty directory like.

deleteDirectory('folderPath');

You can get more detail about above function from here.

If you face any issue after using this function write the comment below.

How to remove html tags from string using PHP

How to remove HTML tags from string programmatically. let’s see the two easy way to remove HTML tags from the string using “strip_tags” and “preg_replace”. So let’s see how to remove HTML code from the string using “strip_tags”.

$string = strip_tags(“Hello <b>world!</b>);

We used the ‘strip_tags’ function for removing the HTML tags from the string. so it’s very easy to remove HTML using “strip_tags”. But the “strip_tags” add space after removing the tags from the string like.

$string = strip_tags(“Hello<b>world!</b>);

The output of the above statement is “Hello world!” instead of “Helloworld!”. so let’s see the another trick for removing only HTML tags without adding the space.

$string = preg_replace(#<[^>]+>#’, ‘ ‘, ‘Hello<b>world!</b>’);

The output of the above function is “Helloworld!” instead of “Hello world!”.

If you face any issue after using this code please write a comment below.

Git remove last commit from remote and local

Git how to remove the last commit from remote and local. Sometimes we are creating the mistake on written commit message or push wrong code by mistake at the time we need to remove that code or commit from remote and local. So let’s see the step for removing the last commit from remote or local.

Make sure before removing any comment from the remote server because that commit also removed for your team member when his push or pull the code from the remote server.

First of all get the git log

git log

The output will look like this on your command prompt

commit 6488b7e23c31f4472b063b8d3c3e15f8dfc91495
Author: thecodingstuff <thecodingstuff@gmail.com>
Date:   Thu Jul 20 10:17:39 2017 -0700

    Add welcome heading tag

commit 69f7c2b25ccf49dcd9ede9f21d33eb5c2b6e6f33
Author: thecodingstuff <thecodingstuff@gmail.com>
Date:   Thu Jul 20 10:14:36 2017 -0700

    first commit

Now copy the commit id like “69f7c2b25ccf49dcd9ede9f21d33eb5c2b6e6f33” from where you want to remove commit on remote or local server.

Now type below command for removing the commit.

git reset --hard 69f7c2b25ccf49dcd9ede9f21d33eb5c2b6e6f33
git push -f origin master

Replace “master” with your branch name.

After following this command your commit was removed from the remote and local server.

If you face any issue after using the above steps please write the comment below.