Web Technology II · Unit 5
String Processing and Regular Expressions
Exam-focused notes for String Processing and Regular Expressions (Web Technology II, BIT301): what the TU syllabus asks and how it has actually been tested, with 4 solved past questions from this unit.
What this unit covers
- String patterns and regular expressions
- String exploding and imploding
- String comparison and approximate equality
- Character access in strings
- String manipulation functions
- CSV file parsing
Character access in strings
Write a program that will read your name as input string. Access and display the individual characters in the name string. [5]
A PHP string is an indexed sequence of characters, and a single character is reached with square brackets exactly as an array element is, so $name[0] is the first character. strlen() returns the length, therefore a counting loop running from 0 up to strlen(...
Full solved answer →String exploding and imploding
What is exploding and imploding of strings? Illustrate with an example. [5]
--- Exploding means splitting a string into an array based on a specified delimiter/separator. In PHP, this is done using the built-in explode() function. - separator - the delimiter used to split the string (required) - string - the input string to be spli...
Full solved answer →String comparison and approximate equality
How is the approximate equality of two strings done in PHP? Write a program to demonstrate it. [5]
In PHP, approximate equality of two strings is performed using the double equals operator (==) with type juggling, or more specifically, the concept of approximate/loose comparison. However, for string similarity/approximate matching, PHP provides the built...
Full solved answer →String patterns and regular expressions
Write a PHP program to illustrate string patterns using regular expression. [5]
Function Purpose ------ pregmatch() Match a pattern (returns true/false) pregmatchall() Find all matches pregreplace() Replace matched pattern pregsplit() Split string by pattern --- --- --- Pattern Meaning ------ ^ Start of string $ End of string [a-zA-Z] ...
Full solved answer →Make Unit 5 stick
Practice BIT301 with flashcards & quizzes