Ma'lumotlar bazasidan tarkibni ko'rsatish

I have table conatining records for different dog breeds , have a page to dispaly dog breeds with name A, I want to show a little description also there, but description field has lot of data , how can i limit it to fixed size when pulling from database and also I want to put read more at the end. http://www.animalswecare.com/Pets/Dogs/a.php

2
Bu juda batafsil ma'lumotga muhtoj. "Qaysidir darajada" degani nimani anglatadi? "Ko'proq o'qiladi" nimani aniq qilishi kerak? Ehtiyot qismini qidirmoqdamiz, masalan. PHP-da paragrafiya
qo'shib qo'ydi muallif Pekka 웃, manba

3 javoblar

2
qo'shib qo'ydi

Agar siz buni SQL-da barcha ma'lumotlarni olishni emas, keyin PHP bilan boshqarishni istasangiz, sql so'rovida SUBSTRING funktsiyasidan foydalaning:

SUBSTRING (dog_description, 0,20) Sizning boshingizdan 20 ta belgilar qatori berilishi mumkin (shu sababli 0,20)

2
qo'shib qo'ydi
Men o'zim uchun qidirayotganim uchun rahmat
qo'shib qo'ydi muallif user995426, manba
Yaxshi, bu ba'zi resurslarni tejaydi. rahmat
qo'shib qo'ydi muallif abruski, manba

Buni ko'ring

function limit_words($string, $word_limit)
{
    $words = explode(" ",$string);
    return implode(" ",array_splice($words,0,$word_limit));
}


$content = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

echo limit_words($content,20);

EDIT.

DaveRandom tomonidan tavsiya etilgan.

function limit_words($string, $word_limit)
{
    $words = str_word_count($string, 1);
    return implode(" ",array_splice($words,0,$word_limit));
}


$content = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

echo limit_words($content,20);
1
qo'shib qo'ydi
FYI, str_word_count() butun "so'zlar" ni mag'lubiyatga chiqarish uchun - bu explode ('', $ string) dan yanada aqlli ish, chunki u har qanday bo'shliqni hisobga oladi ajratuvchi va raqamlar va suzuvchi tinish belgilarini e'tiborsiz qoldiradi
qo'shib qo'ydi muallif DaveRandom, manba
@DaveRandom Ha, siz haqsiz. Javobni tahrirladim.
qo'shib qo'ydi muallif Rupesh Pawar, manba
PhP |BotsUz
PhP |BotsUz
93 ishtirokchilar

Phpni o'rganishni Hohlasangiz https://t.me/joinchat/AAAAAE-KRc5dd5tPMmGmWA A'zo bo'lin