Solved

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

Posted on 2011-09-22
2
258 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
Comment Utility
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 108

Accepted Solution

by:
Ray Paseur earned 500 total points
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now