Solved

str_replace = i need to remove an empty line from my string PLS HELP

Posted on 2011-09-22
2
264 Views
Last Modified: 2012-05-12
My string contains an extra empty line, how can i remove it or replace it?

I am using a .php code for this and i can't make it work
$mystring str_replace("/n","",$mystring)
echo $mystring;

Thanks
0
Comment
Question by:parpaitas
2 Comments
 
LVL 2

Expert Comment

by:shdwmage
ID: 36583257
This is what I use to remove all carriage returns in my input.

function data_correction($beta) {
	//this function is used to replace data copied and pasted from excel to make it into a useable format.
	$newstr = str_replace("\r\n", ",", $beta);
	return $newstr;
};

Open in new window


I paste information from excel and I don't like to seperate it into commas.  Hope that helps.
0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 36583389
This is not a valid PHP statement.  It needs an assignment operator.  And /n is not the same as \n
$mystring str_replace("/n","",$mystring)

Try something more like this:
$mystring = str_replace("\n", NULL, $mystring);

Also, you might want to know about the context-aware constant, PHP_EOL.  It is the end-of-line character.

But all that aside, we cannot really tell what your data looks like or what you want it to look like.  If you want to post your string with the blank line, I will be glad to show you the code you need to remove the empty line.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question