پی ایچ پی سٹرنگ فونکشن

فائلی یہ حروف کا سلسلہ ہوتا ہے، مثلاً "Hello world!"

پی ایچ پی سٹرنگ فونکشن

اس سیکشن میں، ہم عام طور پر استعمال کی جاتی فائلی آپریشن فنکشنوں کو سیکھیں گے。

PHP strlen() فنکشن

strlen() فنکشن نال فائلی کی لمبائی کو حروف کی شمارش سے درج کیا جاتا ہے。

ایک مثال میں، اس فائلی کی لمبائی کو درج کیا جائے گا: "Hello world!"

Example

<?php
echo strlen("Hello world!");
?>

Run Instance

مذکورہ بالا کو کا نتیجہ: 12

Tip:strlen() عام طور پر لوپ اور دیگر فنکشنوں میں استعمال کی جاتی ہے، جب کچھ وقت کو پتہ لگانا اہم ہوتا ہے جب تک کہ فائلی کا آخری حرف کے بعد لوپ کو رکھنا چاہئیے (مثلاً لوپ میں، ہم لوپ کو فائلی کا آخری حرف کے بعد رکھنا چاہئیں جب تک کہ لوپ چل رہا ہو)。

فائلی میں کلمات کا شمارش کرنا

PHP str_word_count() فنکشن نال فائلی کا شمارش کردی:

Example

<?php
echo str_word_count("Hello world!"); // 输出 2
?>

Run Instance

The output of the above code is:

2

Reverse the String

PHP strrev() Function Reverses the String:

Example

<?php
echo strrev("Hello world!"); // Output !dlrow olleH
?>

Run Instance

The output of the above code is:

!dlrow olleH

PHP strpos() Function

The strpos() function is used to search for a specified character or text within a string.

If a match is found, it will return the position of the first matching character. If no match is found, it will return FALSE.

The following example retrieves the text "world" from the string "Hello world!":

Example

<?php
echo strpos("Hello world!","world");
?>

Run Instance

The output of the above code is: 6.

Tip:In the above example, the position of the string "world" is 6. The reason it is 6 (not 7) is that the position of the first character in the string is 0, not 1.

Replace text in the string

The PHP str_replace() function replaces some strings with other strings in a string.

The following example replaces the text "world" with "Kitty":

Example

<?php
echo str_replace("world", "Kitty", "Hello world!"); // Output Hello Kitty!
?>

Run Instance

The output of the above code is:

Hello Kitty!

Complete PHP String Reference Manual

For a complete reference manual of string functions, please visit our PHP String Reference Manual.

This manual provides a brief description and example of each function!