After knowing the strings basics it’s time to know what type of operations we can do with strings.

There are many strings operations we can do…

  • Write a PHP code, for getting any string length & word count.

File – code1.php

$str=”shimanta das microcodes”;
echo “string length is : $len”;
echo “<br> string total words $word”;

Note: strlen() function helps s to know string’s length/size. str_word_count() function helps to know the how many words contains inside a string.

  • Write a PHP code, to reverse a string.

File – code2.php

echo “string is: $str”;
echo “<br>reverse string is: $rev”;

Note: strrev() function is used to reverse a string.

  • Write a PHP code, find a substring inside a full string.

File – code3.php

$str=”i am coder”;
echo strpos($str,”coder”);
echo ‘<br>’;
echo strpos(“rust will replace C”,”C”);
  • Write a PHP code, to replace a substring.

Syntax – str_replace(‘select_replace_word’,’replace_word’,variable/full string)

File – code4.php

$str=”shimanta das owner of microcodes”;
echo “<br>string before: $str”;
$str = str_replace(“microcodes”,””,$str);
echo “<br>string now: $str”;