How can I end a variable name in a string without using space or any other special character?
Example is there anything I can put between $num
and st
to output 1st
instead of 1 st
$num = 1;
echo "$num st";
Without using the dot opperator for concatination
Python String strip() function will remove leading and trailing whitespaces. If you want to remove only leading or trailing spaces, use lstrip() or rstrip() function instead.
Naming rules. Variables can only contain letters, numbers, and underscores. Variable names can start with a letter or an underscore, but can not start with a number. Spaces are not allowed in variable names, so we use underscores instead of spaces.
Variable names cannot contain spaces. A # character in the first position of a variable name defines a scratch variable.
A variable name cannot start with a digit. A variable name can only contain alpha-numeric characters and underscores ( a-z, A-Z , 0-9 , and _ ) Variable names are case-sensitive (age, Age and AGE are three different variables) There is no limit on the length of the variable name.
Wrap the name of the variable with braces.
$num = 1;
echo "${num}st";
Or use printf
syntax instead of simple interpolation:
$num = 1;
printf("%dst", $num);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With