1

Like its a description column which is long but i want to grab some of lines from it on another page ,

 $desc=$result_set['Description'];

which is coming from database i want to echo in a p tag but some of its lines not whole description

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
David
  • 23
  • 5

3 Answers3

1

Use Substr Function and specify start and end position

<?php
$start=0;
$end=50;
echo substr($result_set['description'],$start,$end);
?>
Keerthivasan
  • 1,651
  • 1
  • 21
  • 47
0

Use substr(). Something like

<?php
$len = 40;
echo substr($result_set['description'],0, $len);

?>

This will shorten your description so to a given value (change 40)

Caspar Wylie
  • 2,818
  • 3
  • 18
  • 32
  • @casper Wyile, you should give start and end to substr function, otherwise it will take only start position, so it will print from 40th character – Keerthivasan Oct 05 '16 at 07:48
0

Use php function substr

<?php
$start=0;
$end=50;
echo substr($result_set['description'],$start, $end);

?>

And also if the data is coming from a text editor or contains tags then please use the striptags as well. As shown below:

<?php
 $start=0;
$end=50;
echo substr(strip_tags($result_set['description']), $start, $end);

?>

This will shorten your description so to a given value (change 50)

Rohit Ailani
  • 910
  • 1
  • 6
  • 19
  • you should give start and end to substr function, otherwise it will take only start position, so it will print from 50th character – Keerthivasan Oct 05 '16 at 07:50