How to show first 5 or some word from a string PHP


In this topic i am going to show you How to show first 5 or some word from a string PHP.

Here we using one file for fetch data.

  1. index.php

Example 1

How to show first 5 word from a string PHP
<!DOCTYPE html>
<html>
<body>
<?php
$inputstring="His photography focuses on landscapes, places, objects and the sense of space and locality they create. He has graduated in
communication design from the National Institute of Design, Ahmedabad and later did my Masters in photography at the University
of Calgary, Canada. I teach occasionally as a visiting faculty at a few art and design schools.R. Aravindan has been working in the
photography, documentation and communication design domains for 20+ years. Working and making images is an interactive
workshop with people from different domains to help them have a broader aspect of vision from a camera.";
$pieces = explode(" ", $db_events["description"]);
$first_part = implode(" ", array_splice($pieces, 0, 5));

echo $first_part."....";
<?php echo $db_events["description"];
?>
</body>
</html>

Example 2

How to show first 10 word from a string PHP

<!DOCTYPE html> <html> <body> <?php $inputstring="His photography focuses on landscapes, places, objects and the sense of space and locality they create. He has graduated in communication design from the National Institute of Design, Ahmedabad and later did my Masters in photography at the University of Calgary, Canada. I teach occasionally as a visiting faculty at a few art and design schools.R. Aravindan has been working in the photography, documentation and communication design domains for 20+ years. Working and making images is an interactive workshop with people from different domains to help them have a broader aspect of vision from a camera."; $pieces = explode(" ", $db_events["description"]); $first_part = implode(" ", array_splice($pieces, 0, 10)); echo $first_part."...."; <?php echo $db_events["description"]; ?> </body> </html>

Related Topic

Fetch data show in select box

Fetch data show in checkbox

Fetch data show in radio button

Fetch data show in text box