Jump to content

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"

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.