beedie Posted September 16, 2008 Share Posted September 16, 2008 I have a file with sentences each on a new line. I want to split the string to get each sentence as it's own string. I just need to know the format of a carriage return in a split function I imagine this is very simple but my little brain didn't catch it. My text has a whole line in between each sentence if that makes it easier. Help appreciated Link to comment https://forums.phpfreaks.com/topic/124419-solved-split-a-string-by-a-new-line/ Share on other sites More sharing options...
Garethp Posted September 16, 2008 Share Posted September 16, 2008 Try using \n or \r or \n\r. Like split("\n\r", $Text); Link to comment https://forums.phpfreaks.com/topic/124419-solved-split-a-string-by-a-new-line/#findComment-642507 Share on other sites More sharing options...
beedie Posted September 16, 2008 Author Share Posted September 16, 2008 This gives me : Notice: Undefined offset: 4 $sentence = split("\r\n",$word); echo $sentence[4]; Link to comment https://forums.phpfreaks.com/topic/124419-solved-split-a-string-by-a-new-line/#findComment-642518 Share on other sites More sharing options...
Garethp Posted September 16, 2008 Share Posted September 16, 2008 $Text = "1 2 3 4"; $Text = split("\n", $Text); Will split Text into seperate lines for you. Link to comment https://forums.phpfreaks.com/topic/124419-solved-split-a-string-by-a-new-line/#findComment-642520 Share on other sites More sharing options...
beedie Posted September 16, 2008 Author Share Posted September 16, 2008 Thanks Garethp. I knew it would be as simple as that. Link to comment https://forums.phpfreaks.com/topic/124419-solved-split-a-string-by-a-new-line/#findComment-642526 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.