String In PHP

 There are following string functions in PHP:

strlen() - in return the length of string.

<?php
echo strlen("Learn PHP by RK"); // outputs 15
?>


str_word_count() - Count Words in a String

<?php
echo str_word_count("Learn PHP by RK"); // outputs 4
?>


strrev() - Reverse a String

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


strpos() - Search For a Text Within a String

<?php
echo strpos("Hello world!""world"); // outputs 6
?>


str_replace() - Replace Text Within a String

<?php
echo str_replace("world""Dolly""Hello world!"); // outputs Hello Dolly!
?>


Thanks for reading. I hope It helps.

Donate Me

Comments

Popular posts from this blog

PHP Variables

PHP Comments

PHP Operators