Answer : PHP doesn’t have built-in function like Right and Left function in the MYSQL commands.
Use the following function to get right or left character in PHP String
Left Function PHP
1 2 3 | function left($str, $length) { return substr($str, 0, $length); } |
How to use :
1 | left('Sigit Prasetya', 5) |
The Result :
Right Function PHP
1 2 3 | function right($str, $length) { return substr($str, -$length); } |
How To Use :
1 | left('Sigit Prasetya', 8) |
The Result :
Conclusion:
Using the PHP substr represents the right and left functions. But with the above code we can simplify usage.
Leave a Reply