Jump to content

[SOLVED] Getting rid of HTML tags


soycharliente

Recommended Posts

I tried searching the forums for this, but I can't find the right words to type in and not get back a bunch of unrelated stuff.

Maybe this has already been asked, if so, please point me there.

 

I'm trying to grab just the text from a db entry for a blog. I don't want any HTML formatting. It may have line breaks, list tags, image tags, etc.

 

--------------------

If this is a sample post.

 

Here's a line break.

 

<img src="img/image.jpg" style="float:left;" /> And skip over the image to get this text.

--------------------

 

Make sense?

Link to comment
https://forums.phpfreaks.com/topic/95429-solved-getting-rid-of-html-tags/
Share on other sites

I tried writing something, but it doesn't seem to be working. Nothing is happening. The test string comes back exactly the same.

 

<?php
$content = $row["post_content"];
while (strpos($content, "<") !== FALSE) {
$start = strpos($content, "<");
$end = strpos($content, ">", $start);
$content = substr_replace($content, "", $start, $end-$start);
}
echo $content;
?>

Your code looks good to me... have you tried echoing your start and end variables to see if they appear in the right places?

 

hold on your right it is leagle i checke dit sorry, i very rarley check memory for memory thats very deep

 

 

saying ">" !== blah is wrong because they are identical but not the same thing maybe ?

Thank you all. I didn't know about strip_tags() which was very helpful. No need to reinvent the wheel.

 

This is what I ended up using:

<?php
$content = substr(strip_tags($row["post_content"]), 0, 75);
echo "<p>{$thedate} <a href=\"{$guid}\" title=\"Read {$title}\">{$title}</a> {$content}[...]</p>";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.