Skip to main content

Php preparation

<!DOCTYPE html>

<html>

<body>


<?php

$x = 'adnan';

$$x = 'zaib';


echo $$x;

echo "</br>";

echo $adnan;

echo "</br>";

echo "what is is the use of &";

echo "</br>";


$a = '1';

$b = &$a;

echo $b;

echo "</br>";

$b = "2$b";

echo $a.','.$b; //21,21 q k b point kr rha ha as a reeferece variable to $a mtlb: $b jo ha wo $a variable ki memory ko point kr rha hai


echo "</br>";

$x = 5;


echo $x+++$x++; //11

echo "</br>";

echo "<br />";

echo $x---$x--; // 1

echo "<br />";



$array[10] = 'adnan';


print_r($array);

print($array[10]);


echo '</br> length: '. count($array);

echo '</br>';



$y = "man"; $$y = 100; echo $y; echo $$y; echo $man;

echo '</br>';



$text = 'adnan';

echo strlen($text);

echo '</br>';

$text[10] = 'zaib'; //array([10] => zaib)


print_r($text);



?> 


</body>

</html>




1: What is the output of the following code:

   $a = '1';

   $b = &$a;

   $b = "2$b";

   echo $a.", ".$b;

 

2: What will this code output and why?

    $x = true and false;

    var_dump($x);

 

3: What will be the output of the code below?

  $x = 5;

  echo $x;

  echo "<br />";

  echo $x+++$x++;

  echo "<br />";

  echo $x;

  echo "<br />";

  echo $x---$x--;

  echo "<br />";

  echo $x;

4: Output of following code?

<?php $y = "man"; $$y = 100; echo $y; echo $$y; echo $man; ?>

 

5: After the code below is executed, what will be the value of $text and what will strlen($text) return? Explain your answer.

$text = 'John ';

$text[10] = 'Doe';

 

 

6: Loop Through Array : 

   $input_array = array("aaa", "b", "b", "b","b","b", "b","b");

    $output_array = array();

    for ($i = 0; $i < count($input_array); $i++)

    {

        $temp =  $input_array[!isset($input_array[$i-1]) ? $i  : $i-1];

        $input_array[!isset($input_array[$i-1]) ? $i  : $i-1] = $input_array[!isset($input_array[$i-1]) ? $i : $i];

        $input_array[!isset($input_array[$i-1]) ? $i : $i]   = $temp;

        array_push($output_array,$input_array);

     }

     print_r($output_array);



solution


Array
(
    [0] => Array
        (
            [0] => aaa
            [1] => b
            [2] => b
            [3] => b
            [4] => b
            [5] => b
            [6] => b
            [7] => b
        )

    [1] => Array
        (
            [0] => b
            [1] => aaa
            [2] => b
            [3] => b
            [4] => b
            [5] => b
            [6] => b
            [7] => b
        )

    [2] => Array
        (
            [0] => b
            [1] => b
            [2] => aaa
            [3] => b
            [4] => b
            [5] => b
            [6] => b
            [7] => b
        )

    [3] => Array
        (
            [0] => b
            [1] => b
            [2] => b
            [3] => aaa
            [4] => b
            [5] => b
            [6] => b
            [7] => b
        )

    [4] => Array
        (
            [0] => b
            [1] => b
            [2] => b
            [3] => b
            [4] => aaa
            [5] => b
            [6] => b
            [7] => b
        )

    [5] => Array
        (
            [0] => b
            [1] => b
            [2] => b
            [3] => b
            [4] => b
            [5] => aaa
            [6] => b
            [7] => b
        )

    [6] => Array
        (
            [0] => b
            [1] => b
            [2] => b
            [3] => b
            [4] => b
            [5] => b
            [6] => aaa
            [7] => b
        )

    [7] => Array
        (
            [0] => b
            [1] => b
            [2] => b
            [3] => b
            [4] => b
            [5] => b
            [6] => b
            [7] => aaa
        )

)

 

 

 

7: Remove Colon ( : ) from each date time exists in string.

     $string = "Lorem Ipsum is simply dummy text : 2022-07-19 12:12:56 Contrary to popular belief, Lorem Ipsum is not simply random text: 2022-07-19 23:12:56 . There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form 14:12:56".

New String should be:

 $string = "Lorem Ipsum is simply dummy text : 2022-07-19 12 12 56 Contrary to popular belief, Lorem Ipsum is not simply random text: 2022-07-19 23 12 56 . There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form 2022-07-19 14 12 56".

 

 solution

$string = "Lorem Ipsum is simply dummy text : 2022-07-19 12:12:56 Contrary to popular belief, Lorem Ipsum is not simply random text: 2022-07-19 23:12:56 . There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form 14:12:56.";


// Define a regular expression pattern for detecting times

$pattern = '/\b(?:\d{2}:\d{2}:\d{2}|\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\b/';


// $pattern = '/\b\d{2}:\d{2}:\d{2}\b/';


preg_match_all($pattern,$string, $matches);


// print_r($matches);


foreach($matches[0] as $match){

$formatedString = str_replace(':','',$time);

    $string = str_replace($time,$formatedString,$string);

}


echo $string;

 

8 : Write a mysql query to remove duplicate cliente having unique telefono without creating new table. Table name xtable.  Remaining dataset will

Dataset :

    DROP TABLE IF EXISTS `xtable`;

CREATE TABLE `xtable` (

  `cliente` varchar(255) DEFAULT NULL,

  `telefono` varchar(255) DEFAULT NULL,

  `telefono2` varchar(255) DEFAULT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

 

INSERT INTO `xtable` (`cliente`, `telefono`, `telefono2`) VALUES

('lavaggio', '', NULL);

INSERT INTO `xtable` (`cliente`, `telefono`, `telefono2`) VALUES

('cisco', '', '3333');

INSERT INTO `xtable` (`cliente`, `telefono`, `telefono2`) VALUES

('ibm', '555', '');

INSERT INTO `xtable` (`cliente`, `telefono`, `telefono2`) VALUES

('gsoftware', '4444', '6728'),

('gsoftware', '4444', ''),

('gsoftware', '', ''),

('gsoftware', '8320', ''),

('cisco', NULL, NULL),

('lavaggio', NULL, NULL),

('gsoftware', '4444', ''),

('ibm', '555', ''),

('gsoftware', '4444', '6728'),

('gsoftware', '', '4444');

Output:

       Cliente             telefono            telefono2

       lavaggio           Empty               NULL

       cisco                 Empty                3333

       ibm                   555                     Empty

       gsoftware        4444                  6728

      gsoftware         8320                  Empty

      ace                     1212                 1212

 


Comments

Popular posts from this blog

Install MariaDB Latest Version 11.4 in Red Hat Version 9

 This this post i will show you step by step the installation process of mariaDB in red hat version 9. Step1 Run the command to pull the latest updated packages on applications installed in your system. -dnf update If you get Kernal update than reboot the system -reboot Step2 Go to official mariaDB site Make mariadb repository in /etc/yum.repos.d Place the configuration in this file # MariaDB 11.4 RedHatEnterpriseLinux repository list - created 2024-09-24 11:12 UTC # https://mariadb.org/download/ [mariadb] name = MariaDB # rpm.mariadb.org is a dynamic mirror if your preferred mirror goes offline. See https://mariadb.org/mirrorbits/ for details. # baseurl = https://rpm.mariadb.org/11.4/rhel/$releasever/$basearch baseurl = https://mirrors.aliyun.com/mariadb/yum/11.4/rhel/$releasever/$basearch # gpgkey = https://rpm.mariadb.org/RPM-GPG-KEY-MariaDB gpgkey = https://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB gpgcheck = 1 Now install the mariaDB with its dependencies package...

Linux Commands

  Linux Commands 1.  OS-Release -cat /etc/os-release -cat /etc/redhat-release show os //kernal information -uname  show kernal middleware It is intermediator between hardware and software. -uname  -r what is process architect. -uname -p To show all information -uname -a 2.  Date-CAL -date -cal 3.  Booting in Linux (Run-Levels) Shutdown/Close pc -init 0  Single user mode -init 1 Multiple user mode -init 2 Multiple user mode with network plus full support Not use -init 4 Graphical mode init 5 Reboot the system -init 6 4.  Target command in Linux (systemctl) With the help of target we can manage system specific as well as user specific task. Target command is system Control (systemctl). Basically it is utility, which build to replace 'init' command. What systemctl can do ?  We can find its all commands with the help of single command. write systemctl enter twice TAB button. //it will list all its commands. Show current system mode - systemctl...