siddscool19 Posted September 4, 2008 Share Posted September 4, 2008 Can anyone tell me how to take one line from a variable? Like for example i store information from a textarea in a variable. Now i want to execute each line one by one how to do that? Can anyone help me please? Link to comment https://forums.phpfreaks.com/topic/122683-take-one-line-from-a-variable/ Share on other sites More sharing options...
JasonLewis Posted September 4, 2008 Share Posted September 4, 2008 You can use the explode() function on the new line breaks (\n) then loop through each line. Link to comment https://forums.phpfreaks.com/topic/122683-take-one-line-from-a-variable/#findComment-633510 Share on other sites More sharing options...
siddscool19 Posted September 4, 2008 Author Share Posted September 4, 2008 Can u please tell me the meaning of this also while(1) i don;t want to start a new thread thats why asking here PLease tell also this $link = "<div style=\"text-align: center;\"> Why did we add \ in "<div style=\" I mean what does \ gives output here Link to comment https://forums.phpfreaks.com/topic/122683-take-one-line-from-a-variable/#findComment-633514 Share on other sites More sharing options...
JasonLewis Posted September 4, 2008 Share Posted September 4, 2008 That will just create in infinite loop in which you will eventually need to break out of. Or it'll just keep looping. Link to comment https://forums.phpfreaks.com/topic/122683-take-one-line-from-a-variable/#findComment-633520 Share on other sites More sharing options...
siddscool19 Posted September 4, 2008 Author Share Posted September 4, 2008 Please reply to my second part also Link to comment https://forums.phpfreaks.com/topic/122683-take-one-line-from-a-variable/#findComment-633524 Share on other sites More sharing options...
JasonLewis Posted September 4, 2008 Share Posted September 4, 2008 The back-slash is escaping the quotes. See how the variable is opened with double-quotes (") then the div tag requires double-quotes also. If you didn't have the back-slash in front of the quote PHP would throw an error at you. Link to comment https://forums.phpfreaks.com/topic/122683-take-one-line-from-a-variable/#findComment-633527 Share on other sites More sharing options...
siddscool19 Posted September 4, 2008 Author Share Posted September 4, 2008 Thank you for all the above But can u tell me how to use explode function ??? I am not able to get how to use it to get one line from a variable containing many lines Link to comment https://forums.phpfreaks.com/topic/122683-take-one-line-from-a-variable/#findComment-633528 Share on other sites More sharing options...
JasonLewis Posted September 4, 2008 Share Posted September 4, 2008 If the data is coming from a textarea tag then you can use it like so: $text = $_POST['textarea']; $explode = explode(PHP_EOL, $text); //Using PHP_EOL, which is a predefined constant for the End Of Line in different OS foreach($explode as $lines){ echo $line . "<br>"; //Echo out each line, you can perform whatever you need on the $line } Link to comment https://forums.phpfreaks.com/topic/122683-take-one-line-from-a-variable/#findComment-633530 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.