scarhand Posted November 4, 2008 Share Posted November 4, 2008 lets say i have a paragraph like this: hello there how are you today i am doing fine i really am what is the simplest way i can have php only echo this: i am doing fine i really am Quote Link to comment https://forums.phpfreaks.com/topic/131355-solved-getting-a-paragraph-to-not-display-first-4-lines/ Share on other sites More sharing options...
n3ightjay Posted November 4, 2008 Share Posted November 4, 2008 wheres the text / paragraph coming from ? database ? Quote Link to comment https://forums.phpfreaks.com/topic/131355-solved-getting-a-paragraph-to-not-display-first-4-lines/#findComment-682139 Share on other sites More sharing options...
rhodesa Posted November 4, 2008 Share Posted November 4, 2008 <?php $text = 'hello there how are you today i am doing fine i really am'; list(,,,,$trimmed) = explode("\n",$text,5); print $trimmed; ?> Quote Link to comment https://forums.phpfreaks.com/topic/131355-solved-getting-a-paragraph-to-not-display-first-4-lines/#findComment-682142 Share on other sites More sharing options...
rhodesa Posted November 4, 2008 Share Posted November 4, 2008 or...with a variable to adjust the number of lines skipped: <?php $text = 'hello there how are you today i am doing fine i really am'; $skip = 4; $parts = explode("\n",$text,$skip+1); print $parts[$skip]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/131355-solved-getting-a-paragraph-to-not-display-first-4-lines/#findComment-682144 Share on other sites More sharing options...
scarhand Posted November 4, 2008 Author Share Posted November 4, 2008 its coming from a database, wrapped with the nl2br function also, how would i remove ONLY the 3rd line? thanks so far rhodesa! Quote Link to comment https://forums.phpfreaks.com/topic/131355-solved-getting-a-paragraph-to-not-display-first-4-lines/#findComment-682146 Share on other sites More sharing options...
Adam Posted November 4, 2008 Share Posted November 4, 2008 that would depend, are they all going to be split into new lines or would word wrap effect the lines to remove? It they are proper new lines, then you could use: $lines = explode("\n", $text); for ($i = 4; $i <= count($lines); $i++) { print $line . "\n"; } One of many ways I imagine.. Adam Quote Link to comment https://forums.phpfreaks.com/topic/131355-solved-getting-a-paragraph-to-not-display-first-4-lines/#findComment-682149 Share on other sites More sharing options...
Adam Posted November 4, 2008 Share Posted November 4, 2008 to not show line 3.. $lines = explode("\n", $text); for ($i = 0; $i <= count($lines); $i++) { if ($i != 2) print $line . "\n"; } Remember array's start at 0 .. so it's index 2 in the array not 3.. Quote Link to comment https://forums.phpfreaks.com/topic/131355-solved-getting-a-paragraph-to-not-display-first-4-lines/#findComment-682151 Share on other sites More sharing options...
rhodesa Posted November 4, 2008 Share Posted November 4, 2008 its coming from a database, wrapped with the nl2br function also, how would i remove ONLY the 3rd line? thanks so far rhodesa! ...using my imagination: <?php $text = 'hello there how are you today i am doing fine i really am'; $lines = explode("\n",$text); unset($lines[2]); //Line 3 has an index of 2 $new_text = implode("\n",$lines); print $new_text; ?> Quote Link to comment https://forums.phpfreaks.com/topic/131355-solved-getting-a-paragraph-to-not-display-first-4-lines/#findComment-682152 Share on other sites More sharing options...
Adam Posted November 4, 2008 Share Posted November 4, 2008 Oops, on both my examples should be: print $lines[$i] . "\n"; Quote Link to comment https://forums.phpfreaks.com/topic/131355-solved-getting-a-paragraph-to-not-display-first-4-lines/#findComment-682154 Share on other sites More sharing options...
scarhand Posted November 4, 2008 Author Share Posted November 4, 2008 thanks Quote Link to comment https://forums.phpfreaks.com/topic/131355-solved-getting-a-paragraph-to-not-display-first-4-lines/#findComment-682161 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.