Jump to content

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.

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.