-2

I am trying to take part of a text in php.

I'm talking about, for example taking "Hello my name is..." from "Hello my name is John Doe, I am a computer engineer".

Is it possible to do this with php and how would I do this?

UPDATE: I want to return the first 20 characters and "..."

Jens Vam
  • 1
  • 1
  • 8

1 Answers1

0

You can use substr to do accomplish this, and then append the ... after taking the first twenty characters.

<?php

$input_string = "Hello my name is John Doe, I am a computer engineer.";

$text = substr($input_string, 0, 20) . '...';

print $text;

Which prints out:

Hello my name is Joh...
Lando
  • 419
  • 3
  • 8