Even need 3 signs.
|
5 answers
The correct way: use mb_substr()
$input = 'в углу скребёт мышь'; // исходная строка $toDelete = 3; // сколько знаков надо убрать mb_internal_encoding("UTF-8"); $result = mb_substr( $input, $toDelete); // глу скребёт мышь
Wrong example:
$input = 'в углу скребёт мышь'; // исходная строка $toDelete = 3; // сколько знаков надо убрать $result = substr( $input, $toDelete); // углу скребёт мышь
Because Cyrillic characters are double-byte, "in" takes two bytes, a space - one. Therefore, not three characters were cut off, but only two.
|
substr($text,2); // удалит первые три символа
- fivePlus-responding this answer has something to do with the phenomenon of g *** coderiness. To think laziness, to test the more. Somewhere heard about the mentioned f-yu, okay. $ text = 'abcdef'; echo substr ($ text, 2). PHP_EOL; // cdef - only the first two characters were deleted $ text = 'abvgde'; echo substr ($ text, 2). PHP_EOL; // bwgde - only one is missing - Sergiks
- Yes, there are a lot of advantages and truths, I didn’t even understand why =) - Salivan
|
$s = '12345678'; $s = preg_replace( '/^.(.*)$/', '\1', $s ); echo "$s\n"; // вывод: 2345678 $s = preg_replace( '/^./', '', $s ); echo "$s\n"; // вывод: 345678
- 2@klopp; It’s not reasonable to use a regular function where a built-in function is provided for this. - Deonis
- In the statement of the task and the word there was neither rationality nor goals :) And, judging by the question, I need to expand my horizons ... how to expand ... - user6550
|
<?php $tekst = "absdefghi"; $tekst=substr($tekst,1,0); echo $tekst; ?>
- five0 - remove $ tekst = substr ($ tekst, 1); Or add the string length $ tekst = substr ($ tekst, 1, strlen ($ tekst)); But the first option is better - Deonis
|
$matn="salom"; $matn=substr($matn,1); echo $matn; //выводит: alom //или $matn="salom"; $matn=substr($matn,3); echo $matn; //выводит: om //ещё вариант $matn="salom"; $matn=substr($matn,-1); echo $matn; //выводит: salo //или $matn="salom"; $matn=substr($matn,3); echo $matn; //выводит: sa
- Such an answer has already been given above.stackoverflow.com/a/135868/177188 and criticized. - Kromster
|