Write a PHP script to demonstrate the following string functions:

 


1. strlen()


2. strrev()


3. strpos()


4. str_replace()


5. substr()


Source Code:


<?php


$text "Hello, PHP world!";


$length = strlen($text);


echo "Length of the string: Slength"."<br>";


Sreversed strrev($text);


echo "Reversed string: $reversed","<br>";


$position = strpos($text, 'PHP');


echo "Position of 'PHP": $position","<br>";


$replaced = str_replace('world', 'everyone', $text);


echo "String after replacement: $replaced","<br>";


$substring substr($text, 7, 3);


echo "Substring (7 to 10): Ssubstring","<br>"; ?>

Comments

Popular posts from this blog

Calculate Factorial using While loop in JavaScript.

Calculator

Simple calculator