How to trim a string on the right side?strstr($i, $y, true)
does not work due to the low version of PHP
3 answers
substr( $i, 0, strpos( $i , ".jpg") )
?
zzyzh pro expansion is also true W)
- no, guys, you didn’t understand me ... after .jpg there are more ~ 3000 sigmols and they always have a different number, I need to cut off exactly by the line entry - igolka97
- Well? returns the string cut to the first occurrence of
.jpg
, if you usestrrpos
, then by the last entry ... read the description of the functions though ... or specify the question, at the moment our options correspond to your task. - thunder - @thunder Thank you very much everything works)) - igolka97
|
substr($string, $from, $count);
- I will add the answer @ ToRcH565 <? Php $ rest = substr ("abcdef", -1); // returns "f" $ rest = substr ("abcdef", -2); // returns "ef" $ rest = substr ("abcdef", -3, 1); // returns "d"?> - thunder
- @thunder I need a search for a string entry and not a character count ( - igolka97
- cited the example above, what's the difference, this is the basics) - thunder
|
And what prevents to find an index with the help of strpos
/ strrpos
, and take a substring?
substr($i, 0, strrpos($i, $y))
For PHP versions less than 5, you need a cycle, see the @thunder comment:
$pos = 0; $found = false; do { $newpos = strpos($i, $y, $pos); if ($newpos !== false) { $pos = $newpos; $found = true; } } while ($newpos !== false); if ($found) $i = substr($i, 0, $pos); else ...
- suppose I need to cut .jpg into the distilleryimage10.instagram.com/… HOW? - igolka97
- @ igolka97:
.jpg
- is it a constant, or a variable? Or do you want to cut off the extension? - VladD - 2substr ($ i, 0, strpos ($ i, ".jpg"))? - thunder
- one@ igolka97: look at @thunder above. Only need
strrpos
. (Updated the answer.) - VladD - one@VladD may not roll, since> 5.0.0 depends on the version of the PCP. 5.0.0 > 5.0.0 The offset parameter was introduced. - thunder
|