Categories: PHP

How to show only 50 words using PHP

Try this code for following Pupose

  1. Php show only first 50 characters
  2. how to show only 50 words using php
  3. Php limit string to 50 words
  4. Display limited text in PHP
  5. Get first 50 characters string php

you can adjust number of character i mean if you need to show only 20 character then need to change 50 to 20

Here are two method which one you understand just use them in your code

<?php

$in=”Pellentesque habitant morbi tristique senectus eter netus et malesuada fames ac turpis egestas. Morbi purus nisl, blandit et eros id, pharetra tristique massa. Nulla facilisi. Curabitur lobortis urna eu neque congue, id cursus purus placerat. In malesuada est tellus. Nunc ac ullamcorper nibh. Maecenas lacus dolor, volutpat sed augue sit amet, maximus condimentum sem. Aenean nec egestas orci. Sed fringilla augue eget arcu consectetur interdum. Praesent sed dignissim risus. Ut lobortis dolor nec sagittis dapibus. Donec eget dolor vitae elit porta commodo in et magna. Nunc sapien nisl, euismod ac ex vitae, sodales feugiat lorem. Phasellus condimentum, nulla cursus porta mollis, nulla urna dapibus velit, vitae sagittis arcu risus vitae orci. Praesent leo nisi, laoreet id mauris nec, hendrerit feugiat lacus. Praesent vulputate lorem vel lobortis aliquam.”;

?>

Method:1

<?= $out = strlen($in) > 50 ? substr($in,0,50)."..." : $in;?>

Method:2
$result = substr($in, 0, 50); //first 50 chars “Pellentesque habitant morbi tristique senectus eter”

Basant

Recent Posts

How to make dependent dropdown of state and district using cakephp2 form?

Creating dependent dropdowns in CakePHP 2 involves using AJAX to dynamically load data into the…

18 hours ago

How to make id as auto increment in postgrey SQL?

just add below code in column properties id Default input Method: 1nextval('form_submissions_id_seq'::regclass) Method: 2 Via…

21 hours ago

How to Add Auto Increment to a Column in PostgreSQL ?

Learn how to efficiently set up auto-increment columns in PostgreSQL with this step-by-step guide. From…

1 month ago