Hello
I have a field which have more than 2 lines of text in it. I get it from database into array. What i want to do is to show only the first 2 lines.
Any help appreciated.
Thanks
Array problem
Moderator: General Moderators
- greenhorn666
- Forum Commoner
- Posts: 87
- Joined: Thu Aug 14, 2003 7:14 am
- Location: Brussels, Belgium
Code: Select all
$str = substr($str, 0,
strpos($str, "\n",
strpos($str, "\n")));of the first newline in the string $str, starting looking for it after the first newline!
Isn't that a nice sentence???
Well it should do it at least...
or using regex...
i'm honestly not sure which is faster - using regex or the strpos solution greenhorn suggested... i have a feeling it is the strpos one.
Code: Select all
preg_match("/^.*\n.*\n/",$str, $matches);
echo $matches[0];yes, the escape sequence "\n" selects newline characters
find more here - http://www.php.net/manual/en/pcre.pattern.syntax.php
find more here - http://www.php.net/manual/en/pcre.pattern.syntax.php
-
digitalquake
- Forum Newbie
- Posts: 5
- Joined: Wed Aug 20, 2003 1:52 am
-
digitalquake
- Forum Newbie
- Posts: 5
- Joined: Wed Aug 20, 2003 1:52 am