RGS
RGS

Reputation: 4253

how to remove first and last \n from string? PHP

I have a problem in a variable in PHP that I want to remove the first and last \n from a string but not the \n in the text.

eg:

<--------------\n //I want to remove this (if exists)
some text \n
some text \n
<--------------\n //I want to remove this (if exists)

Any ideas?

Upvotes: 1

Views: 1864

Answers (2)

Mindsers
Mindsers

Reputation: 662

Trim PHP function makes what you want to do : All whitespaces before and after string are removed.

$someText = "   bulbul   ";
echo trim($sometext); // "bulbul"

Upvotes: 3

AP 2022
AP 2022

Reputation: 787

trim() strips whitespace from the beginning and end of a string. I believe this is what you need. More on the trim() function: http://php.net/manual/en/function.trim.php

Upvotes: 0

Related Questions