dadamssg87 Posted August 25, 2011 Share Posted August 25, 2011 How do i get the first part of the string, all the way up until the string hits a line break? <?php $string = "The quick red fox\n jumped over the brown\n lazy dog."; function first_of_string($str) { //php magic return $first_of_string; } echo first_of_string($string); //would produce "The quick red fox" ?> Quote Link to comment https://forums.phpfreaks.com/topic/245649-get-string-before-line-break/ Share on other sites More sharing options...
jcbones Posted August 25, 2011 Share Posted August 25, 2011 <?php $string = "The quick red fox\n jumped over the brown\n lazy dog."; function first_of_string($str) { //php magic return strstr($first_of_string, "\n",true); // -> php 5.3.0 } echo first_of_string($string); //would produce "The quick red fox" ?> Quote Link to comment https://forums.phpfreaks.com/topic/245649-get-string-before-line-break/#findComment-1261650 Share on other sites More sharing options...
dadamssg87 Posted August 25, 2011 Author Share Posted August 25, 2011 just what i needed. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/245649-get-string-before-line-break/#findComment-1261655 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.