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? Quote Link to comment 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; ?> Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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; Quote Link to comment 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 ? Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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>"; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.