CS Knowledge Opener - Logo
CS Knowledge
Opener
Facebook Youtube Telegram
  • Home
  • 12th CS
    • 12th CS English Medium
    • 12th CS Tamil Medium
  • 12th CA
    • 12th CA English Medium
    • 12th CA Tamil Medium
  • 11th CS
    • 11th CS English Medium
    • 11th CS Tamil Medium
  • 11th CA
    • 11th CA English Medium
    • 11th CA Tamil Medium
  • CS / CA Question Bank
  • Other Subjects
  • Student Alerts
  • Govt Exams
  • Home
  • 12th CS
    • 12th CS English Medium
    • 12th CS Tamil Medium
  • 12th CA
    • 12th CA English Medium
    • 12th CA Tamil Medium
  • 11th CS
    • 11th CS English Medium
    • 11th CS Tamil Medium
  • 11th CA
    • 11th CA English Medium
    • 11th CA Tamil Medium
  • CS / CA Question Bank
  • Other Subjects
  • Student Alerts
  • Govt Exams
CS Knowledge Opener - Logo
CS Knowledge
Opener
Facebook Youtube Telegram
  • Home
  • 12th CS
    • 12th CS English Medium
    • 12th CS Tamil Medium
  • 12th CA
    • 12th CA English Medium
    • 12th CA Tamil Medium
  • 11th CS
    • 11th CS English Medium
    • 11th CS Tamil Medium
  • 11th CA
    • 11th CA English Medium
    • 11th CA Tamil Medium
  • CS / CA Question Bank
  • Other Subjects
  • Student Alerts
  • Govt Exams
  • Home
  • 12th CS
    • 12th CS English Medium
    • 12th CS Tamil Medium
  • 12th CA
    • 12th CA English Medium
    • 12th CA Tamil Medium
  • 11th CS
    • 11th CS English Medium
    • 11th CS Tamil Medium
  • 11th CA
    • 11th CA English Medium
    • 11th CA Tamil Medium
  • CS / CA Question Bank
  • Other Subjects
  • Student Alerts
  • Govt Exams
12th CA English Medium

Practical program exercise 9 PHP String Functions for 12th computer applications

Baskaran J
February 17, 2023 2 Mins Read
1.4K Views
0 Comments

Practical program 9 PHP String Functions

String

  • String is a sequence characters.
  • The language comes with a full-featured library of built-in functions that let you do everything from reversing and splitting strings to calculating logarithmic values.

Using String Functions

  • PHP has over 75 built-in string manipulation functions, supporting operations ranging from string repetition and reversal to comparison and search-and-replace.

Checking for Empty Strings

  • The empty() function returns true if a string variable is “empty.”
  • Empty string variables are those with the values ”, 0, ‘0’, or NULL.
  • The empty() function also returns true when used with a non-existent variable.

strlen()

  • Calculates the number of characters in a string
  • The strlen() function returns the number of characters in a string.

str_word_count()

  • Calculates the number of words in a string
  • PHP’s str_word_count() function provides an easy way to count the number of words in a string.

strrev()

  • Reverses a string

str_replace()

  • Replaces parts of a string
  • PHP also has the str_replace() function, designed specifically to perform find-and-replace operations.
  • This function accepts three arguments: the search term, the replacement term, and the string in which to
    perform the replacement.

Using Constants

  • PHP containers for values that remain constant and never change.
  • Constants are defined using PHP’s define() function, which accepts two arguments: the name of the constant, and its value.
  • Constant names must follow the same rules as variable names, with one exception: the $ prefix is not required for constant names.

Concatenating Strings

  • To combine strings, use PHP’s concatenation operator, which happens to be a period (.).

 

CA – 9 PHP – STRING FUNCTIONS

QUESTION:

  • Write a PHP code to demonstrate the usage of string functions in PHP.

AIM:

  • To create and execute String Functions in PHP.

PROCEDURE:

  1. Start Xampp server (Apache)
  2. Go to virtual path folder (C:\xampp\htdocs)
  3. Create test.php file and type the program
  4. Execute the program on your Web browser using by this URL link (http://localhost/test.php)

PROGRAM:

<html>

<body>

<?php

echo strlen(“Hello World!”).'<br>’;

echo str_word_count(“Good Morning Teachers”).”<br>”;

echo strrev(“welcome”) . “<br>”;

echo strpos(“Hello world!”,”world”).”<br>”;

echo str_replace(“Hi”,”Hello”,”Hi Everyone”).”<br>”;

define(“GREETING”,”Good Morning”);

echo GREETING.”<br>”;

$text = ‘PHP Tutorial’;

$text = preg_replace(‘/(\b[a-z])/i’,'<span style=”color:red;”>\1</span>’,$text);

echo $text;

?>

</body>

</html>

OUTPUT:

12

3
emoclew
6
Hello Everyone
Good Morning

PHP Tutorial

RESULT:

The Output was verified successfully

Tags:

Practical

Share Article

Follow Me Written By

Baskaran J

Other Articles

Previous

Practical program exercise 8 PHP Create & Execute Echo and Print Statements for 12th computer applications

Next

Practical program exercise 10 PHP Converting word to digit for 12th computer applications

Next
February 18, 2023

Practical program exercise 10 PHP Converting word to digit for 12th computer applications

Previous
February 16, 2023

Practical program exercise 8 PHP Create & Execute Echo and Print Statements for 12th computer applications

No Comment! Be the first one.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

twenty − fifteen =

Related Posts

12th CA Board Exam Answer Key Discussion 2024-2025

Baskaran J
March 14, 2025

12th Computer Applications English medium Program Question 2024-2025

Baskaran J
February 23, 2025

12th Computer Applications Practice One marks question 2024-2025

Baskaran J
February 3, 2025

12th Computer Applications English medium Public Exam Important Question 2024-2025

Baskaran J
January 16, 2025

Subscribe to our newsletter and stay updated.

CS Knowledge Opener

CS Knowledge Opener focuses on 11th &12th Computer Science & Computer Applications English Medium & Tamil Medium. Programming Skills and also we are Publishing Study Materials Based on New syllabus introduced by TNSCERT. (TNBOARD).

Quick Links

  • Contact Us
  • About Us
  • Privacy Policy
  • Disclaimer
  • Terms and Conditions
Categories
11th CA English Medium 15
11th CA Tamil Medium 9
11th CS English Medium 21
11th CS Tamil Medium 12
12th CA English Medium 32
12th CA Tamil Medium 8
12th CS English Medium 36
12th CS Tamil Medium 12
Government Exams 36
Notifications 8
Other Subjects 13

Follow Us

Youtube
Facebook
Telegram
CS Knowledge Opener © 2020 - 2025. All Rights Reserved.