---
title: "PHP String function"  
description: "In this article I will describe some basic string function which is used in php. Let’s we have a brief idea about it.  Concatenation Operator in PHP:T"  
author: "Anonymous User"  
published: 2011-09-07  
updated: 2020-03-04  
canonical: https://www.mindstick.com/articles/719/php-string-function  
category: "php"  
tags: ["php"]  
reading_time: 3 minutes  

---

# PHP String function

In this article I will describe some basic string function which is used in php. Let’s we have a brief idea about it.\

##### Concatenation Operator in PHP:

The concatenation operator is used to put two string values together. Concatenation operator is define by ‘.’(Dot) sign.

Let’s we have an example, how to concatenate two string values using concatenation operator (.).

##### Example:

```
<html>     <head>         <title>Concatenation Operator Demo</title>    </head><body>        <?php              //  Declare first string              $str1 = "Hello";                //  Declare second string              $str2 = "word";                            //  Concatenate str1 and str2              $result = $str1." ".$str2;                            // display result               echo $result;       ?></body></html>
```

##### Output:

![PHP String function](https://www.mindstick.com/mindstickarticle/4550476c-822d-4506-b41f-edf5ec8228a7/images/f20cb815-afc2-4abb-aa4c-65684029893c.png)

##### strlen () function :

In PHP, strlen() function is used to return the length of string.

Let’s we have an example, how to use strlen() function in php.

##### Syntax: strlen (string value);

##### Example:

```
<html>     <head>         <title>Calculate String Length  </title>    </head><body>        <?php              //  Declare string type  variable              $lenDemo = "This is a demo string to calculate its length";                //  calculate length of string              $calstrlen   =   strlen($lenDemo);                             echo "String length is:" .  $calstrlen  ;                          ?></body></html>
```

##### Output:

![PHP String function](https://www.mindstick.com/mindstickarticle/4550476c-822d-4506-b41f-edf5ec8228a7/images/8f00e535-eb43-4668-ab81-dadb608e644b.png)

##### strops() function:

The strpos() function is used to search for a character/text within a string. i.e. with the help of strpos() function you can search a specific character or specific text string. If match is found, strops() function will returns character position of first match. If no match is found, it will return false (Nothing to display).

##### Syntax: strops(string strname, value);

Let’s we have an example, how to search a character or text within a string.

Case 1: If string or character founds in given string.

##### Example:

```
<html>     <head>         <title>Searching string in PHP</title>    </head><body>        <?php              //  Declare the string              $lenDemo = "This is a demo string to calculate its length";                //  Search character               echo "character position is:". strpos($lenDemo,  'h')."</br>";                            //  Search string                 echo "String position is:".strpos($lenDemo,"to") ;                             ?></body></html>
```

##### Output:

![PHP String function](https://www.mindstick.com/mindstickarticle/4550476c-822d-4506-b41f-edf5ec8228a7/images/4b8b4a5e-64a9-4b95-bb05-cd2e1bd4f606.png)

Case 2: If string or character doesn’t found in given string.

##### Example:

```
<html>     <head>         <title>Searching string in PHP</title>    </head><body>        <?php              //  Declare the string              $lenDemo = "This is a demo string to calculate its length";                //  Search character               echo "character position is:". strpos($lenDemo,  'z')."</br>";                            //  Search string                 echo strpos($lenDemo,"go") ;                         ?></body></html>
```

##### Output:

![PHP String function](https://www.mindstick.com/mindstickarticle/4550476c-822d-4506-b41f-edf5ec8228a7/images/5ad405da-3c83-4398-9194-81260b8f7e08.png)

Note: Searching index start from 0.

\

---

Original Source: https://www.mindstick.com/articles/719/php-string-function

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
