PHP Programming

Hands On No. 7 : Working with Strings in PHP

Working with Strings in PHP

strlen() - Return the Length of a String

                                

<?php
echo strlen(" Hi Hello NUV! "); // outputs 12
?>

str_word_count() - Count Words in a String
 

<?php
echo str_word_count(" Hi Hello NUV! "); // outputs 2
?>

strrev() - Reverse a String
                             

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

strpos() - Search For a Text Within a String
                               

<?php
echo strpos(" Hi Hello NUV! ", "NUV"); // outputs 6
?>

str_replace() - Replace Text Within a String
                               

<?php
echo str_replace("Nuv", "NUV", " Hi Hello Nuv!!"); // outputs Hello NUV!
?>