Jump to content

replace new line with new line and |?


onedumbcoder

Recommended Posts

I am trying to replace '\n' with '\n |'

 

but when I do this preg_replace('[\n]', '\n | ', $messeage) the results is a string that shows the '\n'

 

for example if i have

 

Hi I am

someone

 

I want it to show up as

 

|Hi I am

|someone

 

instead i am getting

 

\n |Hi I am\n |someone

 

I cant just do preg_replace('[\n]', '| ', $messeage) because then I will lose the new lines

Link to comment
Share on other sites

I was thinking and i slipped sorry.

 

Hehe, I was just kidding buddy!

 

 

I think someone (*caugh*Maq*cough*) is just jealous they aren't a top 10 poster.

 

Aww man, you got me, figured me out...  Did you have to go there?

Link to comment
Share on other sites

A quick and dirty test on my server, 100,000 tests of each:

for($i=0;$i<100000;$i++) 
$x = str_replace(' x ','', $string);

And

for($i=0;$i<100000;$i++) 
$x = preg_replace('~ x ~','', $string);

Showed 0.157774925232 seconds and 0.217579841614 seconds, respectively. Tried about 10 times, about the same results each time.

Link to comment
Share on other sites

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.