Jump to content

get string before line break


dadamssg87

Recommended Posts

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"

?>

Link to comment
https://forums.phpfreaks.com/topic/245649-get-string-before-line-break/
Share on other sites

<?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"

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.