'Remove first and last word from a string(php))
I want to remove the first and last word from a string.
$string = "12121";
I tried trimming it like
$string = "12121";
$trimmed = trim($string, 1);
print($trimmed);
Result
22
And I want
212
So please help me
Solution 1:[1]
can you try this?
<!DOCTYPE html>
<html>
<body>
<?php
$string = "12121";
$temp = ltrim($string, 1);
$trimmed = rtrim($temp, 1);
print($trimmed);
?>
</body>
</html>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Romil Dhanani |
