<< < 9 10 11 12 13 14 15 >   Sort: Rank

Ways to Include Variables in Double-Quoted Strings in PHP
How Many Ways to Include Variables in Double-Quoted Strings? There are 3 formats to include variables in double-quoted strings: "part 1 $variable part 2" - This is the simplest format to include a variable in a string. The variable name starts with the dollar sign and ends at the first character tha...
2016-10-13, 260👍, 0💬

Escape Sequences in Double-Quoted Strings in PHP
How Many Escape Sequences Are Recognized in Double-Quoted Strings? There are 12 escape sequences you can use in double-quoted strings: \\ - Represents the back slash character. \" - Represents the double quote character. \$ - Represents the dollar sign. \n - Represents the new line character (ASCII ...
2016-10-13, 260👍, 0💬

Assigning a New Character in a String in PHP
How To Assigning a New Character in a String? The string element expression, $string{index}, can also be used at the left side of an assignment statement. This allows you to assign a new character to any position in a string. Here is a PHP script example: <?php $string = 'It\'s Friday?'; echo "$s...
2016-10-13, 255👍, 0💬

PHP Built-in Functions for Strings
Where to find tutorials and answers to frequently asked questions for PHP Built-in Functions for Strings? A collection of frequently asked questions on manipulating strings in PHP. Clear answers are provided with tutorial exercises on string functions including strlen, trim, substr, chop, strpos, st...
2016-10-13, 253👍, 0💬

Comparing Two Strings in PHP
How To Compare Two Strings with Comparison Operators? PHP supports 3 string comparison operators, <, ==, and >, that generates Boolean values. Those operators use ASCII values of characters from both strings to determine the comparison results. Here is a PHP script on how to use comparison ope...
2016-10-13, 251👍, 0💬

Including Array Elements in Double-Quoted Strings in PHP
How Many Ways to Include Array Elements in Double-Quoted Strings? There are 2 formats to include array elements in double-quoted strings: "part 1 $array[key] part 2" - This is called simple format. In this format, you can not specify the element key in quotes. "part 1 {$array['key']} part 2" - This ...
2016-10-13, 251👍, 0💬

Converting Numbers to Strings in PHP
How To Convert Numbers to Strings? In a string context, PHP will automatically convert any numeric value to a string. Here is a PHP script examples: <?php print(-1.3e3); print("\n"); print(strlen(-1.3e3)); print("\n"); print("Price = $" . 99.99 . "\n"); print(1 . " + " . 2 . " = " . 1+2 . "\n"); ...
2016-10-13, 249👍, 0💬

Including Variables in Double-Quoted Strings in PHP
How To Include Variables in Double-Quoted Strings? Variables included in double-quoted strings will be interpolated. Their values will be concatenated into the enclosing strings. For example, two statements in the following PHP script will print out the same string: <?php $variable = "and"; echo ...
2016-10-13, 248👍, 0💬

Converting Strings to Numbers in PHP
How To Convert Strings to Numbers? In a numeric context, PHP will automatically convert any string to a numeric value. Strings will be converted into two types of numeric values, double floating number and integer, based on the following rules: The value is given by the initial portion of the string...
2016-10-13, 245👍, 0💬

Accessing a Specific Character in String in PHP
How To Access a Specific Character in a String? Any character in a string can be accessed by a special string element expression: $string{index} - The index is the position of the character counted from left and starting from 0. Here is a PHP script example: <?php $string = 'It\'s Friday!'; echo ...
2016-10-13, 245👍, 0💬

Concatenating Two Strings in PHP
How To Concatenate Two Strings Together? You can use the string concatenation operator (.) to join two strings into one. Here is a PHP script example of string concatenation: <?php echo 'Hello ' . "world!\n"; ?> This script will print: Hello world!   ⇒Understanding PHP String Literals and Oper...
2016-10-13, 243👍, 0💬

Remove Trailing New Line Character in PHP
How To Remove the New Line Character from the End of a Text Line? If you are using fgets() to read a line from a text file, you may want to use the chop() function to remove the new line character from the end of the line as shown in this PHP script: <?php $handle = fopen("/tmp/inputfile.txt", "r...
2016-10-13, 242👍, 0💬

Counting the Number of Characters in PHP
How To Count the Number of Characters in a String? You can use the "strlen()" function to count the number of characters in a string. Here is a PHP script example of strlen(): <?php print(strlen('It\'s Friday!')); ?> This script will print: 12   ⇒PHP Built-in Functions for Strings ⇒⇒PHP Tutor...
2016-10-13, 241👍, 0💬

Removing Leading and Trailing Spaces in PHP
How To Remove Leading and Trailing Spaces from User Input Values? If you are taking input values from users with a Web form, users may enter extra spaces at the beginning and/or the end of the input values. You should always use the trim() function to remove those extra spaces as shown in this PHP s...
2016-10-13, 240👍, 0💬

Comparing Two Strings with strcmp() in PHP
How To Compare Two Strings with strcmp()? PHP supports 3 string comparison operators, <, ==, and >, that generates Boolean values. But if you want to get an integer result by comparing two strings, you can the strcmp() function, which compares two strings based on ASCII values of their charact...
2016-10-13, 269👍, 0💬

Joining Multiple Strings in PHP
How To Join Multiple Strings into a Single String? If you multiple strings stored in an array, you can join them together into a single string with a given delimiter by using the implode() function. Here is a PHP script on how to use implode(): <?php $date = array('01', '01', '2006'); $keys = arr...
2016-10-13, 254👍, 0💬

Replacing Characters in a String in PHP
How To Replace a Group of Characters by Another Group? While processing a string, you may want to replace a group of special characters with some other characters. For example, if you don't want to show user's email addresses in the original format to stop email spammer collecting real email address...
2016-10-13, 250👍, 0💬

Splitting a String in PHP
How To Split a String into Pieces? There are two functions you can use to split a string into pieces: explode(substring, string) - Splitting a string based on a substring. Faster than split(). split(pattern, string) - Splitting a string based on a regular expression pattern. Better than explode() in...
2016-10-13, 238👍, 0💬

Testing the strpos() Return Value in PHP
What Is the Best Way to Test the strpos() Return Value? Because strpos() could two types of values, Integer and Boolean, you need to be careful about testing the return value. The best way is to use the "Identical(===)" operator. Do not use the "Equal(==)" operator, because it does not differentiate...
2016-10-13, 237👍, 0💬

Converting Strings to Hex Numbers in PHP
How To Convert Strings to Hex Numbers? If you want convert a string into hex format, you can use the bin2hex() function. Here is a PHP script on how to use bin2hex(): <?php $string = "Hello\tworld!\n"; print($string."\n"); print(bin2hex($string)."\n"); ?> This script will print: Hello world! 4...
2016-10-13, 232👍, 0💬

Taking a Substring in PHP
How To Take a Substring from a Given String? If you know the position of a substring in a given string, you can take the substring out by the substr() function. Here is a PHP script on how to use substr(): <?php $string = "beginning"; print("Position counted from left: ".substr($string,0,5)."\n")...
2016-10-13, 232👍, 0💬

Converting Strings to Upper/Lower Case in PHP
How To Convert Strings to Upper or Lower Cases? Converting strings to upper or lower cases are easy. Just use strtoupper() or strtolower() functions. Here is a PHP script on how to use them: <?php $string = "PHP string functions are easy to use."; $lower = strtolower($string); $upper = strtoupper...
2016-10-13, 230👍, 0💬

Applying UUEncode to a String in PHP
How To Apply UUEncode to a String? UUEncode (Unix-to-Unix Encoding) is a simple algorithm to convert a string of any characters into a string of printable characters. UUEncode is reversible. The reverse algorithm is called UUDecode. PHP offeres two functions for you to UUEncode or UUDecode a string:...
2016-10-13, 226👍, 0💬

Replacing a Substring in PHP
How To Replace a Substring in a Given String? If you know the position of a substring in a given string, you can replace that substring by another string by using the substr_replace() function. Here is a PHP script on how to use substr_replace(): <?php $string = "Warning: System will shutdown in ...
2016-10-13, 224👍, 0💬

<< < 9 10 11 12 13 14 15 >   Sort: Rank