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 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 ? 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; ?> 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]; ?> 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! 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 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.. 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; ?> 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"; 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 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
Archived
This topic is now archived and is closed to further replies.