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
https://forums.phpfreaks.com/topic/236508-preceded-by-newline/#findComment-1215959
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
https://forums.phpfreaks.com/topic/236508-preceded-by-newline/#findComment-1216351
Share on other sites

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.