-2

I want to create a description of the post. This description is taken from the content of the post, which may include html tags but I want not to include the html tags like <html>, <script> and so on.

For example:
I have some content as follows:

<html>ajsdhasudhasidyuai</html>

and I want to get the first 2 characters and without the <html> tag, so the result should be

aj

How can I achieve that?

alariva
  • 2,051
  • 1
  • 22
  • 37
AntKing
  • 39
  • 1
  • 7

1 Answers1

0

You can achieve this with PHP code:

$extract = substr( strip_tags($content), 0, 2);

This will:

  • Strip all HTML tags from your content string
  • Take the first 2 chars (substring) from the clean content
  • Return aj for your given example.

You may want to create a helper function or class to achieve this but this is your starting point.

See example here

alariva
  • 2,051
  • 1
  • 22
  • 37