---
title: "PHP String Function"  
description: "Here we will look on some of the function of strings:strlen()To get the length of the string.example:   $t=\"hello\";  echo strlen($t);  Result: 5  str_"  
author: "zack mathews"  
published: 2016-06-07  
updated: 2018-03-15  
canonical: https://www.mindstick.com/blog/11146/php-string-function  
category: "php"  
tags: ["php", "string"]  
reading_time: 1 minute  

---

# PHP String Function

Here we will look on some of the [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) of [strings](https://www.mindstick.com/forum/161912/explain-the-python-strings):

**strlen()** **:**To get the [length](https://www.mindstick.com/interview/1915/what-is-the-difference-between-char_length-and-length) of the [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp).example:

```
<?php$t="hello";echo strlen($t);?>
```

**[Result](https://www.mindstick.com/blog/12011/advantages-of-getting-result-oriented-seo-from-an-agency):** 5\

**str_word_count** **:** count the number of words

```
<?phpecho str_word_count("Hello world!"); ?>
```

**Result:**

2

**strrev()****:** It is used to [reverse](https://www.mindstick.com/blog/63740/what-are-the-most-effective-and-safest-thanks-to-reverse-erectile-dysfunction) the string\

```
<?phpecho strrev("Good Morning!"); ?>
```

**[Output](https://www.mindstick.com/forum/161319/how-does-the-print-function-handle-output-in-python):**

!gninroM dooG

**strpos() :** [Search](https://www.mindstick.com/blog/301883/why-you-shouldn-t-trust-ai-search-engines) for specific text with in a string:

```
<?phpecho strpos("Hello world!", "r");?>
```

**Output:** 8\

**str_replace****:**[Replace](https://yourviews.mindstick.com/view/81330/cow-antibody-research-in-usa-a-step-ahead-to-replace-plasma-therapy) one [character](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character) from other character.

```
<?phpecho str_replace("Morning" , "afternoon","Good Morning");?>
```

**Output:**

Good afternoon

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