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...

How to find out if a package is installed in Linux?

1) How to find out if a package is installed or not in Linux There are multiple ways to check find locate package is installed in linux machine or not 1.a) Using which command The  ‘which’  command returns an executable path that can be executed when the command is entered in the terminal. # which vi /usr/bin/vi 1.b) Using whereis command The  ‘whereis’  command is used to search the binary, source, and man page files for a given command. # whereis vi vi: /usr/bin/vi /usr/share/man/man1/vi.1p.gz /usr/share/man/man1/vi.1.gz 1.c) Using locate command The  ‘locate’  command performs faster than the find command because it uses an updatedb database, whereas the find command searches in real time. # locate --basename '\nano' /usr/bin/nano /usr/share/nano /usr/share/doc/nano 2) How to find out whether a package is installed or not in Linux, using package manager 2.a) On CentOS / Red Hat (RHEL) 6/7 Use  yum command  or  rpm command  to deter...

Default login form code in laravel

  <div class="container">     <div class="row justify-content-center">         <div class="col-md-8">             <div class="card">                 <div class="card-header">{{ __('Login') }}</div>                 <div class="card-body">                     <form method="POST" action="{{ route('login') }}">                         @csrf                         <div class="form-group row">                             <label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>         ...