Improve php programming skills

Here we have bunch of task improving php programming, this kind of program always make in C, C++, java and c#, now to time implement in PHP programming

TASK 1:Print triangle number in reverse pattern

Need output like below
6 5 4 3 2 1
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1

1
2
3
4
5
6
7
8
9
10
11
<?php
for($i=6;$i>=1;$i--)
{
    for($j=$i;$j>=1;$j--){  
        echo $j." ";
            if($j==1){    
                echo "<br/>"; 
             }
    }
}
?>

TASK 2:Print triangle number

Need output like below
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6

1
2
3
4
5
6
7
8
9
10
<?php
for($i=1;$i<=6;$i++){
      for($j=1;$j<=$i;$j++){
        echo $j." ";
        if($j==$i){
            echo "<br/>";
        }
      }
}
?>

TASK 3:Floyd triangle number

Need output like below
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21

1
2
3
4
5
6
7
8
9
10
11
12
<?php
$num=1;
for($i=1;$i<=6;$i++){
      for($j=1;$j<=$i;$j++){
            echo $num." ";
            $num++;
            if($j==$i){
                echo "<br/>";
            }
      }   
}
?>

TASK 4:Print triangle number in reverse pattern

Need output like below
1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
6 5 4 3 2 1

1
2
3
4
5
6
7
8
9
10
<?php
for($i=1;$i<=6;$i++){
        for($j=$i;$j>=1;$j--){
              echo $j." ";
                  if($j==1){
                      echo "<br/>";
                  }
        }  
}
?>

TASK 5:Diamond triangle

Need output like below
—–1
—-2 2
—3 3 3
–4 4 4 4 4
-5 5 5 5 5 5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
 for($i=1;$i<=5;$i++){  
    for($k=5;$k>=$i;$k--)
    {
        echo "-";
    } 
     for($j=1;$j<=$i;$j++)
    {     
             echo $i." ";
             if($j==$i){
                echo "<br/>";
             }
      }
 }
?>

If you often install new plugin and new theme , upgrade plugin and theme that time WordPress ask for ftp credentials, Here is simple code snippet to change the filesystem method and make sure WordPress won’t ask ftp credentials.

 First Method

Paste the following line in your wp-config.php file.

1
define('FS_METHOD', 'direct');

Second Method

Just put your FTP credentials directly in wp-config.php like this:

1
2
3
define( 'FTP_USER', 'username' );
define( 'FTP_PASS', 'pass' );
define( 'FTP_HOST', 'ftp.example.com' );

 

How to change a WordPress site URL

Sometimes you may need to change the URL of your WordPress site. For example, it is a common practice to develop the new version of your site in a sub folder and when it is ready to move it into your root directory. WordPress, however, relies on its URL settings to work correctly. This means that if you simply move your files and database it will not work properly. The URL settings are located in the application database.

Edit wp-config.php

It is possible to set the site URL manually in the wp-config.php file.
Add these two lines to your wp-config.php, where “thecodedeveloper.com” is the correct location of your site.

 

1
2
define('WP_HOME','http://thecodedeveloper.com');
define('WP_SITEURL','http://thecodedeveloper.com');
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
 
	$agent = $_SERVER['HTTP_USER_AGENT'];
 
if (stristr($agent, 'iPhone') == TRUE || stristr($agent, 'iPod') == TRUE || stristr($agent, 'iPad') == TRUE) 
         {
 
	    echo 'iPhone or iPod Touch detected';
            // put code here which you want to run for iphone and ipad
 
	    } else {
 
	    echo 'iPhone or iPod Touch not detected';
           // put code here which you want to run for desktop
 
	    }
 
 
?>