How to Use PHP to Delete All Folders and Files?

Some web hosting companies do not allow us to use “system(‘rm -rf ./*’); ” to delete contents, but we do really need to delete all sub folders and files quickly, how to then?

The follow php code can help us:

<DOCTYPE html>
<meta charset=”utf-8″ />
<?php
function delDirAndFile( $dirName )
{
if ( $handle = opendir( “$dirName” ) ) {
while ( false !== ( $item = readdir( $handle ) ) ) {
if ( $item != “.” && $item != “..” ) {
if ( is_dir( “$dirName/$item” ) ) {
delDirAndFile( “$dirName/$item” );
} else {
if( unlink( “$dirName/$item” ) )echo “Files deleted successfully? $dirName/$item\n”;
}
}
}
closedir( $handle );
if ( rmdir( $dirName ) ) echo “Files deleted successfully: $dirName\n”;
}
}
// delDirAndFile( ‘wap’);  del a folder called: wap
delDirAndFile( ‘./’);  //del all sub folders and files under the current folder
?>
Posted in Php Code. Comments Off on How to Use PHP to Delete All Folders and Files? »

How to Let X-Cart Display latest WordPress Posts?

This mod assumes that you use the WordPress blogging software and uses the same database as your xcart software.
If your wordpress and x-cart use separate database then use this code for blog_headlines.php (more…)

Posted in MySQL, Php Code, WordPress, X-Cart. Comments Off on How to Let X-Cart Display latest WordPress Posts? »

PHP Codes Do Not Working!

Yestday I uploaded a php page to my php VPS hosting from hostgator, i uploaded the file via ‘Secure File Transfer Client’, and I log in my hosting using the username of ‘root’, and its related passwords.

After I uploaded the file, and run the php page, I can not let it working. After about 30 minutes thinking, I found that the hosting directory is belong to a username called ‘eyeglasses’, not ‘root’.

I logged in the centos system via SecureCRT, and run: (more…)

Posted in Php Code. Comments Off on PHP Codes Do Not Working! »

Get first letter of each word


< ?php //get first letter of each word //method a $words = explode(" ", "Cheap prescription eyeglasses"); $acronym = ""; foreach ($words as $w) { $acronym .= $w[0]; } echo $acronym; (more…)

Posted in Php Code, Php Skills. Comments Off on Get first letter of each word »

Static Pages Link Display

How to stop part of static pages showing at homepage, help section, or both?

1. Not show at homepage only
Open file bottom.tpl, which is under fold of skin/2-columns/customer/, and change the following code:

{foreach from=$pages_menu item=p}
{if $p.show_in_menu eq 'Y'}

  • {$p.title|amp}
  • {/if}
    {/foreach}

    to:

    {foreach from=$pages_menu item=p}
    {if $pages_menu[pg].orderby gt "900"}

  • {$p.title|amp}
  • {/if}
    {/foreach}

    Posted in Php Code, X-Cart. Comments Off on Static Pages Link Display »

    Skills on How to Show different Adsense Ads at WordPress

    More and more people love to use wordpress to setup blogs and place adsense ads, and many people still love the use the theme of Classic, by Dave Shea. Can we show different adsense code at the same place, but different pages then? For example, we want to show 2 adsense block at the main body of detailed pages, but only show 1 adsense block at other page’s main body.
    (more…)

    Posted in Php Code, Php Skills, Php Study, WordPress. Comments Off on Skills on How to Show different Adsense Ads at WordPress »

    How to using PHP to delete wordpress coments?

    Sometimes there are thousands wordpresss comments there, it is too difficult to delete them. Any method to delete them one time without login phpmyadmin?

    The answer is yes, the follow code can help you.

    include(‘wp-config.php’);
    mysql_query(“truncate table wp_comments;”);

    Copy the code to file delete_wp_comment.php, and put the file under your blog. Run it, all comments will be deleted!

    If you only want to delete spam or trash comments, please visit http://kingphp.com/160.html , and just change some code. Very simple!

    Posted in MySQL, Php Code. Comments Off on How to using PHP to delete wordpress coments? »

    Using PHP to Export Mysql Data to Excel

     

    <?php 
    $DB_Server = “localhost”;   
    $DB_Username = “put your user name here”;   
    $DB_Password = “put your password here”;   
    $DB_DBName = “put your database name here”;   
    $DB_TBLName = “put your table name here”;   
      
    $savename = date(“YmjHis”);  // excel file name
    $Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password) or die(“Couldn’t connect.”);   
    mysql_query(“Set Names ‘utf-8′”); (more…)

    Posted in MySQL, Php Code. Comments Off on Using PHP to Export Mysql Data to Excel »

    Mass Delete Comments from WordPress

    Pending links, Spam links, or Trash links with a WordPress powered blog can grow really quickly and most is spam. Word Press allows you to remove such comments but only 20 at a time. What if you have thousands pending links, spam links or trash links need to be deleted? You will wast a lot time if you delete them via WordPress Blog own functions. Here we will teach you how to delete them via phpmyadmin! (more…)

    Posted in Php Code, WordPress. Comments Off on Mass Delete Comments from WordPress »

    Some tips on adding ads code to wordpress

    If we do not want ads code shows at wordpress homepage, but at the other pages, we can use the following code:
    <?php if (($wp_query->current_post == 0)and (!is_home())) : ?>
    <div style=”float:right;margin-left:20px”><br>
    Buy sunglasses online.
    </div>
    <?php endif; $postcnt++; ?>

    If we want the ads codes show at all pages, we can use the following codes: (more…)

    Posted in Php Code, WordPress. Comments Off on Some tips on adding ads code to wordpress »
    King Php Science Welcome, you are from: 54.205.172.57