soycharliente Posted March 10, 2008 Share Posted March 10, 2008 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 More sharing options...
soycharliente Posted March 10, 2008 Author Share Posted March 10, 2008 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 https://forums.phpfreaks.com/topic/95429-solved-getting-rid-of-html-tags/#findComment-488604 Share on other sites More sharing options...
nadeemshafi9 Posted March 10, 2008 Share Posted March 10, 2008 strip_tags removes PHP and HTML it may remove \n and \r Link to comment https://forums.phpfreaks.com/topic/95429-solved-getting-rid-of-html-tags/#findComment-488611 Share on other sites More sharing options...
nadeemshafi9 Posted March 10, 2008 Share Posted March 10, 2008 while (strpos($content, "<") !== FALSE) { thats somne crazy coding technique son Link to comment https://forums.phpfreaks.com/topic/95429-solved-getting-rid-of-html-tags/#findComment-488613 Share on other sites More sharing options...
bpops Posted March 10, 2008 Share Posted March 10, 2008 Your code looks good to me... have you tried echoing your start and end variables to see if they appear in the right places? Link to comment https://forums.phpfreaks.com/topic/95429-solved-getting-rid-of-html-tags/#findComment-488615 Share on other sites More sharing options...
nadeemshafi9 Posted March 10, 2008 Share Posted March 10, 2008 try .... $content = strip_tags($row["post_content"]); echo $content; Link to comment https://forums.phpfreaks.com/topic/95429-solved-getting-rid-of-html-tags/#findComment-488616 Share on other sites More sharing options...
nadeemshafi9 Posted March 10, 2008 Share Posted March 10, 2008 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 https://forums.phpfreaks.com/topic/95429-solved-getting-rid-of-html-tags/#findComment-488621 Share on other sites More sharing options...
bpops Posted March 10, 2008 Share Posted March 10, 2008 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 Link to comment https://forums.phpfreaks.com/topic/95429-solved-getting-rid-of-html-tags/#findComment-488627 Share on other sites More sharing options...
haku Posted March 10, 2008 Share Posted March 10, 2008 Not illegal at all. It means not equal to, and doesn't just test for value, but also for type. http://www.devguru.com/technologies/php/6050.asp Link to comment https://forums.phpfreaks.com/topic/95429-solved-getting-rid-of-html-tags/#findComment-488633 Share on other sites More sharing options...
soycharliente Posted March 10, 2008 Author Share Posted March 10, 2008 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 https://forums.phpfreaks.com/topic/95429-solved-getting-rid-of-html-tags/#findComment-488658 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.