I have a variable that gets set from a database field that may have multiple line breaks. I want some php code that splits the text from that variable into 2 separate variables (or a array with 2 values) using ONLY the first line break as the delimiter.
So you understand what I am trying to do, the database field the variable is coming from is a post message and I essentially want to use the first bit of text up to the first line break as the post title and everything after that as the post message.
An example would be as follows:
$myvariable = "Do you believe what happened today? This great big bus almost ran me over. Then I jumped out of the way. Then something else happened and it was more crazy. Finally I decide to go home and have a nap because the day was just going too crazy. I like elephant pants, the fit me SNUGG!";
My new variables would become:
$title_from_myvariable = "Do you believe what happened today?";
$message_from_myvariable = "This great big bus almost ran me over. Then I jumped out of the way. Then something else happened and it was more crazy. Finally I decide to go home and have a nap because the day was just going too crazy. I like elephant pants, the fit me SNUGG!";
I have looked at a few ways to do this using as the delimiter and using explode, and I have looked at PHP_EOL using explode as well.
There are a few great threads about this like the following:
How to put string in array, split by new line?
Explode PHP string by new line
The problem is if I use code like:
$new_array_with_new_variables = explode("
", $myvariable);
or
$new_array_with_new_variables = explode("PHP_EOL", $myvariable);
I end up splitting EVERY new line into a variable...
Any suggestions super coders out there? I just can't figure this one out!