Jump to content

Preceded by newline?


Undrium

Recommended Posts

Sorry I wasn't clear enough, I am writing an assertion and this is how far I have come. I want to preg_replace a word if it does have a whitespace, is the start of string or a newline is preceded. Problem is I do not know how to write newline in the assertion. I know that \s for instance means any whitespace so I have that sorted out.

Link to comment
Share on other sites

It's not doing the trick, though. Sat some hours yesterday with this problem:

 

$s = preg_replace('#(?<=^|\s|\()(http://[^\s\)]+)#', '[url=$1]$1[/url]', $data); 

 

Everything works fine until a newline occurs, if the URL is located after a newline it won't activate. However if I make a space after the newline it will replace. Also it works if the URL is at the start of a string.

 

This will work:

 

Some text
http://www.address.com

 

This won't work:

 

 

Some text
http://www.address.com

 

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.