I am trying to take a text area value and run it through regular expression to split it to lines.
so if someone wrote a line then enter and another line and enter the i will have an array with each line per array value
The expression I’ve came up with so far is :
(.+?)\n|\G(.*)
and this is how i use it(from a website i use to test expressions http://myregextester.com/)
$sourcestring="
this is a sentense yeaa
interesting sentense
yet another sentese
";
preg_match_all('/(.+?)\n|\G(.*)/',$sourcestring,$matches);
echo "<pre>".print_r($matches,true);
however there is 1 object in the array that always empty and i am trying to find a way to get rid of it.
Thanks in advanced.
You don’t need a regex for this, just use
explode(), like so:Now each line of the user’s
$inputwill be a single array entry in$lines.