String Functions
To create
and execute String Functions in PHP
1. Start Xampp server (Apache)
2. Goto virtual path folder (C:\xampp\htdocs)
3. Create funtion.php file and type the program
4. Execute the program on your Web browser using by
this URL link
(http://localhost/ funtion.php)
<html>
<body>
<?php
//Displays the length of the string
echostrlen(“Hello world!”);
//Counting number of words in a
String
echo str_word_count(“Good Morning
All”);
//Reversing a string
echo strrev(“welcome”);
// calculates position of strong
echo strpos(“Hello world!”, “world”);
// replacing the text
echo str_replace(“Hi”, “Hello”, “Hi
Everyone”);
define(“GREETING”, “Good
Morning!!!”);
echo GREETING;
//changes the color of the first character
of a word
$text = ‘PHP Tutorial’;
$text =
preg_replace(‘/(\b[a-z])/i’,’<span
style=”color:red;”>\1</span>’,$text);
echo $text;
?>
</body>
</html>
12
3
emoclew
6
Hello Everyone
Good Morning!!!
PHP Tutorial
Related Topics
Privacy Policy, Terms and Conditions, DMCA Policy and Compliant
Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.