|
|
|
| Доброй ночи ! :))
<?
$text = "Lorem Ipsum is s
imply dummy text
of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since th
e 1500s, when an unknown printer took a galley of type and scrambled it to ma
ke a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remai
ning essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets conta
ining Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker inclu
ding versions of Lorem Ipsum.";
echo preg_replace("/(.{0,10}).*/sui","$1...",$text);
?>
|
Почему показывает на конце 6 точек вместо 3?
если в регулярке вместо * ставить +, то все нормально. Но почему? | |
|
|
|
|
|
|
|
для: ladan
(25.03.2012 в 01:44)
| | Все нормально становится так же, если указать явно начало и конец строки
echo preg_replace("/^(.{0,10}).*$/sui","$1...",$text);
| Зацепляется за конец, в котором не осталось ни одного символа, однако, выражение .{0,10}.* вполне себе подходит под определение пустой строки - вот конечная пустая строка и заменяется, хорошо, что один раз. Чтобы этого избежать можно вместо 0, указать 1
echo preg_replace("/(.{1,10}).*/sui","$1...",$text);
|
| |
|
|
|
|
|
|
|
для: cheops
(25.03.2012 в 03:07)
| | Спасибо большое! | |
|
|
|