scarhand Posted August 20, 2008 Share Posted August 20, 2008 lets say i have content that is formatted like this in my database: line 1 value line 2 value this is some content this is some content this is some content this is some content this is some content this is some content this is some content this is some content this is some content this is some content this is some content this is some content this is some content this is some content this is some content this is some content this is some content this is some content this is some content this is some content this is some content this is some content this is some content this is some content this is some content this is some content how would i get the line 1 and line 2 value? Link to comment https://forums.phpfreaks.com/topic/120522-read-first-to-lines-of-content/ Share on other sites More sharing options...
asmith Posted August 20, 2008 Share Posted August 20, 2008 with str_pos() find the new lines position : $content = line 1 value line 2 value this is some content this is some content this is ... $pos = str_pos($content,"\n"); then with substr() get it : substr($content, 0, $pos); then go for second line : $second = substr($content , $pos); $pos2 = str_pos($second,"\n"); substr($second, 0, $pos2); Link to comment https://forums.phpfreaks.com/topic/120522-read-first-to-lines-of-content/#findComment-621057 Share on other sites More sharing options...
scarhand Posted August 20, 2008 Author Share Posted August 20, 2008 well i had to replace str_pos with strpos and i got the first line to work however, the second line is not working heres my code: <?php $pos = strpos($content,"\n"); $one = substr($content, 0, $pos); $second = substr($content, $pos); $pos2 = strpos($second,"\n"); $two = substr($second, 0, $pos2); Link to comment https://forums.phpfreaks.com/topic/120522-read-first-to-lines-of-content/#findComment-621124 Share on other sites More sharing options...
asmith Posted August 20, 2008 Share Posted August 20, 2008 when you echo the $two what you get ? probably you gotta do this : $second = substr($content, $pos+1); // notice at +1 $pos2 = strpos($second,"\n"); $two = substr($second, 0, $pos2); cause it passes the new line and starts from the first of the second line. Link to comment https://forums.phpfreaks.com/topic/120522-read-first-to-lines-of-content/#findComment-621186 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.