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 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…

4 hours ago

How to get the value of selected radio button using jQuery

Just use below code and modified according to your need. Note: this is very useful…

3 months ago

AWS

Steps: AWS puttyubuntu sudo su apt update apt install apache2 service apache2 start service apache2…

8 months ago