Introduction to PHP syntax Variables Data types and strings


Basic overview of PHP syntax,variables | Data types and strings

PHP syntax Variables Data Types

PHP scripts are written inside the PHP syntax. PHP syntax starts with <?php and ends with ?>. These are known as start-tag and end tag.

For eg:-

<?php
echo 'This is a PHP script';
?>.

Here ‘echo’ is used to display the output of any variable which holds information as a container. We will

discuss the PHP syntax variables data types later on. All the PHP statements end with a semicolon(;).

How to place HTML elements inside the PHP tag

As I told you earlier, a PHP file may contain an HTML element. Here we will see some examples of how to put HTML elements are placed inside the PHP tag one by one.

<?php

?>

   <p>This is a simple text</p>

   $txt = "This is my first paragraph";

   <p><?php echo $txt; ?></p>

<?php

?>

OR

<?php

   <p>This is a simple text</p>

   $txt = "This is my first paragraph";

   echo '<p>'.$txt.'</p>';

?>

In the example above, There are two paragraph elements shown, the first paragraph is used if you want to show the paragraph

element only and the second paragraph element is used to display the output inside the paragraph element in the PHP tag.
or

<?php

 ?>

    <html></html>

 <?php

?>

or

<?php

   ?>
  <table>

     <thead>

        <th>Column name of the table</th>

     </thead>

     <tbody>

  <tr>

     <td><?php echo 'The variable';?> or the value of the column</td>

  </tr>

     </tbody>

 </table>

     <?php

?>

Same consideration is used here

Basic overview of PHP variables

PHP variables are kind of containers where information or data are stored inside the container. PHP variables are declared with a $ sign followed by the name of the variable.

Rules for declaring variables in PHP

  •  A PHP variable should begin with a letter or underscore character.
  • .A PHP variable can contain a mix of letters, numbers and underscore character.

How to assign values to PHP variables

We can assign any kind of value to a PHP variable. Values may contain string values or integer values. For eg—–

<html>

  <body>

   <?php

 $txt = "This is my first PHP sript";

 $int = 10;

       //display the variables

 echo $txt;

 echo "The value of integer variable is ".$int

    ?>

   </body>

</html>

In this example, the integer variable is displayed inside the string with a (.)dot sign. To display the value of a variable with another variable, the (.)dot sign is used between the two variables.

Basic overview of PHP data types

PHP data types are basically string, float, boolean, array, null, etc. We can check the variables using the var_dump() function. It returns the type of the variable.

Below are some of the examples———–

<html>

  <body>

    <?php

     $a = 10;
     $b = 10.5;
     $c = array('English','Bengali','Hindi');
     echo var_dump($a); //it return an integer
     echo var_dump($b);  //it returns floating point
     echo var_dump($c);  //it returns an array

    ?>

   </body>

 </html>

Overview of some important string functions in PHP

The string is a sequence of characters.

strlen():- This function returns the length of the string.

For eg—–
$username = “myname”;
echo strlen($username); // It returns 6.

str_word_count():- This function counts the number of words in a string.

For eg—–
echo str_word_count(“This is my first PHP script”); // It returns 6

strrev():- It reverses the string name.

For eg—–
echo strrev(‘Hello World’); // It displays (dlrow olleh)

strpos():- Search for a specific text within a string.

For eg—–
echo strpos(“Hello world”,’world’); //It displays 6, string count starts from ‘0’.

str_replace():- It replaces text with some other text in a string.

For eg——-
echo str_replace(“hello”,”user”,”Hello friend”); //It returns “user friend”

Also read, a Basic overview of PHP and how it works

Conclusion:- I hope this tutorial will help you to understand the PHP syntax Variables Data Types


2 thoughts on “Introduction to PHP syntax Variables Data types and strings”

  1. Wow, wonderful weblog layout! How lengthy have you ever been blogging
    for? you make running a blog look easy. The overall look of your web site is excellent,
    as neatly as the content material!

    Reply

Leave a Comment

RATU311

RATU311

RATU311

THOR311

THOR311

THOR311

RATU311

RATU311

KUPU178

KUPU178

RATU311

RATU311

RATU311

Mahjong Ways 2

CERI188

CERI188

sv388

CERI188

KUPU178 TOTO SLOT

CERI188

CERI188 TOTO Singapore

KUPU178

RATU311

sabung ayam online

THOR311

parlay

RATU311

KUPU178

RATU311

RATU311

KUPU178

KUPU178

KUPU178

RATU311

RATU311

CERI188

CERI188

KUPU178

RATU311: Alternatif karnpuracollege

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

KUPU178

RATU311

RATU311

RATU311

judi bola

live casino

sv388

sv388

sabung ayam online

sabung ayam online

Thor311 Terbaru

CERI188: Taruhan Bola Sbobet

THOR311 MAHJONG

RATU311: BONUS SABUNG AYAM

CERI188

parlay

KUPU178

RATU311

THOR311

RATU311

RATU311

RATU311

RATU311

RATU311

CERI188

CERI188: Masuk Akun Slot Super Cepat

KUPU178: Slot Online Mahjong Bet 200

THOR311 PRO

THOR311

CERI188

CERI188

CERI188

CERI188

CERI188

CERI188

CERI188

CERI188

THOR311

HOKI311

HOKI311

RATU311

RATU311

KUPU178

THOR311

KUPU178

THOR311

RATU311

HOKI311

KUPU178

KUPU178

RATU311

THOR311 TOTO4D

KUPU178

Live Casino Roullate

RATU311

RATU311

RATU311

RATU311

THOR311

THOR311

THOR311

RATU311

CERI188

DAFTAR KUPU178

LINK DAFTAR CERI188

CERI188

APK KUPU178

KUPU178

CERI188

CERI188

RATU311

KUPU178

THOR311 DOMINO QQ

judi bola online

Mix Parlay

CERI188

CERI188

RATU311

live casino online

RATU311

Mix Parlay

Slot PG Soft

CERI188

RATU311

RATU311

CERI188

THOR311

CERI188

THOR311

Game Thor311

THOR311

HOKI311

live casino

sv388

HOKI311

HOKI311

slot mahjong

Thor311 Alternatif

RATU311

HOKI311

HOKI311

HOKI311

HOKI311

CERI188

THOR311 RESMI

THOR311 AKSES

parlay

HOKI311

THOR311

RATU311 NONTON BOLA

CERI188 Link RTP LIVE

THOR311

Thor311 Live Casino

CERI188

akses VIP THOR311

THOR311

link daftar THOR311

THOR311

situs thor311

RATU311

HOKI311 Link SABUNG AYAM RESMI

HOKI311 Link QRIS EWALLET

RATU311

LINK CERI188

parlay

HOKI311 Link RTP Gacor

HOKI311 Link Apk Resmi

CERI188

KUPU178 Link Daftar

CERI188

CERI188

CERI188

CERI188

CERI188

HOKI311

RATU311

RATU311

HOKI311 Lapak Arena Slot

RATU311 judi bola

HOKI311 Link Spaceman Online

HOKI311 Link Daftar Resmi

CERI188 Toto SGP Online

KUPU178

HOKI311 TEMBAK IKAN ONLINE

KUPU178

HOKI311 Link Login Alternatif

HOKI311 Live Casino Online

HOKI311 Situs Slot Gacor

THOR311

THOR311

situs judi bola

Ceri188 Game Online

CERI188

link login CERI188

link login CERI188

CERI188

THOR311

HOKI311

HOKI311

CERI188

parlay

THOR311

RATU311

HOKI311

HOKI311

HOKI311

RATU311

THOR311

KUPU178

HOKI311

KUPU178

KUPU178

HOKI311

parlay

slot gacor

kupu178 link alternatif

kupu178 slot

kupu178 daftar

kupu178 login

link daftar kupu178

judi bola

HOKI311

RATU311

link alternatif RATU311

Link daftar RATU311

link login RATU311

RATU311

RATU311

KUPU178

KUPU178

THOR311

KUPU178

KUPU178

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

THOR311

KUPU178

KUPU178

HOKI311

THOR311

KUPU178

THOR311

THOR311

slot thailand

judi bola

THOR311

THOR311

KUPU178

THOR311

THOR311

slot gacor

slot gacor

yakuza303

unobet77

slot gacor

slot gacor

RATU311

parlay

parlay

slot gacor

parlay

THOR311