wendu Posted August 1, 2009 Share Posted August 1, 2009 hey I'm trying to do RSS with PHP and currently it's working ok how would I have PHP return only a part of a string that I can use in my RSS description? not just any given part, but words to a fixed point and then take one more word? something line the first line of wordwrap(content, number) Quote Link to comment https://forums.phpfreaks.com/topic/168438-php-only-return-a-part-of-a-string-for-rss-description/ Share on other sites More sharing options...
gevans Posted August 1, 2009 Share Posted August 1, 2009 use wordwrap, the explode by then new line delimiter and print the first result in the array Quote Link to comment https://forums.phpfreaks.com/topic/168438-php-only-return-a-part-of-a-string-for-rss-description/#findComment-888517 Share on other sites More sharing options...
wendu Posted August 1, 2009 Author Share Posted August 1, 2009 thank you since I'm working with paragraphs I thouht I'd do it like this explode("\n", content) and then echo explode[0] works pretty well, thanks Quote Link to comment https://forums.phpfreaks.com/topic/168438-php-only-return-a-part-of-a-string-for-rss-description/#findComment-888543 Share on other sites More sharing options...
.josh Posted August 2, 2009 Share Posted August 2, 2009 What you have right there may not always work out for you. It's an rss feed so you never know what's going to come in. There could be really long paragraphs or something and the \n might come too far down the string. The best way to do it would be to first premove all \n's, then wordwrap, then explode at \n' and use the first exploded element. Alternatively, wordwrap specifying a unique delimiter and explode at that. Quote Link to comment https://forums.phpfreaks.com/topic/168438-php-only-return-a-part-of-a-string-for-rss-description/#findComment-888698 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.