xxxxxxxxxx
<?php
// 6. strtolower()
$str = "HELLO, WORLD!";
echo strtolower($str);
echo "\n";
// Output:
// hello, world!
// 7. ucfirst()
$str = "hello, world!";
echo ucfirst($str);
echo "\n";
// Output:
// Hello, world!
// 8. lcfirst()
$str = "Hello, World!";
echo lcfirst($str);
echo "\n";
// Output:
// hello, World!
// 9. ucwords()
$str = "hello world";
echo ucwords($str);
echo "\n";
// Output:
// Hello World
// 10. trim()
$str = " Hello, world! ";
echo trim($str);
echo "\n";
// Output:
// Hello, world!
?>
xxxxxxxxxx
<?php
// 1. strlen()
$str = "Hello, world!";
echo strlen($str);
echo "\n";
// Output:
// 13
// 2. strpos()
$haystack = "Hello, world!";
$needle = "world";
echo strpos($haystack, $needle);
echo "\n";
// Output:
// 7
// 3. substr()
$str = "Hello, world!";
echo substr($str, 7, 5);
echo "\n";
// Output:
// world
// 4. str_replace()
$str = "Hello, world!";
$newstr = str_replace("world", "PHP", $str);
echo $newstr;
echo "\n";
// Output:
// Hello, PHP!
// 5. strtoupper()
$str = "Hello, world!";
echo strtoupper($str);
echo "\n";
// Output:
// HELLO, WORLD!
?>