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
https://forums.phpfreaks.com/topic/152319-replace-new-line-with-new-line-and/
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.

Archived

This topic is now archived and is closed to further replies.

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