https://github.com/php/php-src
I will learn the String Methods ( Addslaches, Chr, Chop and Chunk_splite ) concepts and examples.
The function returns a text string preceded by backslashes before the characters to be changed. These characters are
Some uses the addslashes () function to prevent "injecting SQL code" (SQL Injection). Instead, the functions of database strings should be used. It has the text string as parameter.
To use the addslaches method you need to pass the " String " as parameter
addslaches($string);
I will use the addslaches method to protect the SQL request from SQL Injection and this the code
$sql = "Select * from Students where idStudent = 1 or ' 1 = 1 ' ";
echo addslashes($sql);
The method will add backslashes before the single quotation and this is the result
The chr () function returns a specified character corresponding to ASCII encoding. This function complements its ord() counterpart. It has the code ASCII as parameter .
To use the Chr method you need to pass the ASCII code
chr(ascii code);
I will pass an ASCII code to the Chr method to get the letter, you can learn about ASCII code from here
echo chr("100");
The representation of ASCII code 100 is the letter " d " and this is the result
The chop() function will remove a white space or other predefined character from the right end of a string. It has two parameters The String and the part that you want to remove.
To use the Chop method you must pass " the String and the word " as parameters
chop($string, "word");
The method will remove from the right end and it will remove the word you passed as parameter
$string = "I love PHP";
echo chop($string, "PHP");
The string is " I love PHP " I want to remove the word PHP and this is the result
The chunk_split () function can be used to divide a text string into small blocks.
It has 3 parameters The first parameter is The body which is The text string to be divided. The second is The length of the block. The third is the End which is the text string that will be inserted in the end.
The chunk_split () function returns the fragmentary text string.
To use the chunk_splite we pass 3 parameters
chunk_splite($string, length, chunklen);
The chunk splite method will devide a string by length using the divider
$stars = "********************";
echo chunk_split($stars, 4 , " | ");
I have a string of stars I want to divide every 4 stars by the separator " | " and this is the result
https://github.com/alexendre-maxim/PHP-Tutorial/blob/master/string1.php