Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: HTML markup problem while displaying trimmed HTML markups

Tags:

html

php

markup

I am using a Richtext box control to post some data in one page. and I am saving the data to my db table with the HTML mark up Ex : This is <b >my bold </b > text

I am displaying the first 50 characters of this column in another page. Now When i am saving, if i save a Sentence (with more than 50 chars )with bold tag applied and in my other page when i trim this (for taking first 50 chars) I would lost the closing b tag (</b>) .So the bold is getting applied to rest of my contents in that page.

How can i solve this ? How can i check which all open tags are not closed ? is there anyeasy way to do this in PHP. Is there any function to remove my entire HTML tags / mark up and give me the sentence as plain text ?

like image 895
Shyju Avatar asked May 13 '26 15:05

Shyju


2 Answers

http://php.net/strip_tags

the strip_tags function will remove any tags you might have.

like image 129
scragar Avatar answered May 16 '26 04:05

scragar


Yes

$textWithoutTags = strip_tags($html);
like image 41
alex Avatar answered May 16 '26 05:05

alex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!