Php Tutorial – CHAPTER 3: Working with strings in PHP
The strings variables are often used to work with all kind of sequence
of text in PHP. We are going to experiment with some examples that will
guide you in this purpose.
<html>
<body>
<head>
<title> MY OWN PHP SCRIPT </title>
</head>
<?php
$String = “PHP is powerful and fast”;
echo $String;
?>
</body>
</html>
The result will be: “PHP is powerful and fast”. The statement “echo”
is used to print or display a result in the screen. Now let’s see
another example where you can put two strings together. The operator
used for do that is the dot (.).
<html>
<body>
<head>
<title> MY OWN PHP SCRIPT </title>
</head>
<?php
$con= “My name is:”;
$nam= “Hector Nicolas”;
echo $con . “ ” . $nam;
?>
</body>
</html>
The result should be: “My name is Hector Nicolas”. On the other hand,
if you desire to measure or count the length of a specific string you
must have to use the function “strlen”. Let’s see a similar example.
<Html>
<head>
<title> MY OWN PHP SCRIPT </title>
</head>
<body>
<?php
echo strlen(“My name is Hector Nicolas”);
?>
</body>
</html>
