kidreapertronV Posted January 2, 2009 Share Posted January 2, 2009 Hello everyone, I'm definitely a beginner... so I really appreciate a resource like this. Thanks! I'm using MySQL v4.1, and PHP5. I'm trying to echo just the first few words of a LONGTEXT string, but the string has html formatting. Ideally, I would like to: [*]display the first few words with the formatting in tact [*]OR get PHP to ignore the html formatting completely Are there any functions that can accomplish this? Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/139219-solved-echoing-first-few-words-wout-displaying-html-formatting/ Share on other sites More sharing options...
.josh Posted January 2, 2009 Share Posted January 2, 2009 You can use strip_tags on your string and then grab the first few words. That not preserve the markup though. Could then take the last word and use some regex to grab entire original string up to last word + any tags that come after it. Quote Link to comment https://forums.phpfreaks.com/topic/139219-solved-echoing-first-few-words-wout-displaying-html-formatting/#findComment-728199 Share on other sites More sharing options...
kidreapertronV Posted January 2, 2009 Author Share Posted January 2, 2009 That works pretty well for my purposes! Thanks! If anyone can think of a way to keep the formatting, it would be appreciated, but this should work for now! Quote Link to comment https://forums.phpfreaks.com/topic/139219-solved-echoing-first-few-words-wout-displaying-html-formatting/#findComment-728212 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.