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
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;
?>

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

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

 

im not sure but from my experience not that i have much !== is ileagle or am i wrong ?

 

Good point :P

Link to comment
Share on other sites

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>";
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.