Broad Network


Changing the Case of Characters in PHP Strings

PHP String with Security Considerations - Part 8

Foreword: In this part of the series I talk about Changing the Case of Characters in PHP Strings.

By: Chrysanthus Date Published: 29 Oct 2018

Introduction

This is part 8 of my series, PHP String with Security Considerations. In this part of the series I talk about Changing the Case of Characters in PHP Strings. You should have read the previous parts of the series before coming here, as this is the continuation.

The lcfirst() Function
This function changes the first character of a string to lower case (if that character is alphabetic). So the code,

<?php

    $str = "This phone text msg is 2 tell yu that I will not do yr thing again.";
    $strl = lcfirst($str);
    echo $strl;

?>

will output,

    “this phone text msg is 2 tell yu that I will not do yr thing again.”.

Note how the function has been used in the code: all the string is the argument to the function.

The ucfirst() Function
This function changes the first character of a string to uppercase (if that character is alphabetic). So the code,

<?php

    $str = ucfirst("this is a sentence.");
    echo $str;

?>

will output,

    This is a sentence.

Note how the function has been used in the code: all the string is the argument to the function.

The strtolower() Function
This function changes all the alphabetic characters in a string to lowercase. The characters that were already in lowercase remain in lowercase. Try the following code:

<?php

    $str = strtolower('THIS is HER THING.');
    echo $str;

?>

All the string is the argument to the function.

The output is:

    this is her thing.

The strtoupper() Function
This function changes all the alphabetic characters in a string to uppercase. The characters that were already in uppercase remain in uppercase. Try the following code:

<?php

    $str = strtoupper('usa, uno, unesco, ussr, uk.');
    echo $str;

?>

The output is:

    USA, UNO, UNESCO, USSR, UK

The ucwords() Function
This function uppercases the first character of each word in a string, that is alphabetic. Try the following code:

<?php

    $str = ucwords('fred and barney's lodge');
    echo $str;

?>

The output is:

    Fred And Barney's Lodge

That is it for this part of the series. What has to be studied next are wordwrap, conversion of different types to string and string to numbers, PHP String Security Risks and Prevention - Explained.

Wordwrap deals with wrapping text to the next line below. In programming, a paragraph is one line of text. You will see details of this in the next part of the series.

Let us take a break here and continue in the next part.

Chrys


Related Links

Basics of PHP with Security Considerations
White Space in PHP
PHP Data Types with Security Considerations
PHP Variables with Security Considerations
PHP Operators with Security Considerations
PHP Control Structures with Security Considerations
PHP String with Security Considerations
PHP Arrays with Security Considerations
PHP Functions with Security Considerations
PHP Return Statement
Exception Handling in PHP
Variable Scope in PHP
Constant in PHP
PHP Classes and Objects
Reference in PHP
PHP Regular Expressions with Security Considerations
Date and Time in PHP with Security Considerations
Files and Directories with Security Considerations in PHP
Writing a PHP Command Line Tool
PHP Core Number Basics and Testing
Validating Input in PHP
PHP Eval Function and Security Risks
PHP Multi-Dimensional Array with Security Consideration
Mathematics Functions for Everybody in PHP
PHP Cheat Sheet and Prevention Explained
More Related Links

Cousins

BACK NEXT

Comments