I have the following string
$text =" Wireless sensor networks (WSNs) enable new applications and
require\r\nnon-conventional paradigms for protocol design due to several
constraints. Owing to the\r\nrequirement for low device complexity together
with low energy consumption (i.e., long\r\nnetwork lifetime), a proper
balance between communication and signal/data processing\r\ncapabilities
must be found. This motivates a huge effort in research activities,
standardization\r\nprocess, and industrial investments on this field since
the last decade.\r\n This survey paper aims\r\nat reporting an overview of
WSNs technologies, main applications and standards, features\r\nin WSNs
design, and evolutions. In particular, some peculiar applications, such as
those\r\nbased on environmental monitoring, are discussed and design
strategies highlighted; a case\r\nstudy based on a real implementation is
also reported. Trends and possible evolutions are\r\ntraced. Emphasis is
given to the IEEE 802.15.4 technology, which enables many applications\r\nof
WSNs. Some example of performance characteristics of 802.15.4-based networks
are\r\nshown and discussed as a function of the size of the WSN and the data
type to be exchanged\r\namong nodes. ";
I want to replace \r\n with nothing only if it was proceeded by dot (.); remove all \r\n but keep .\r\n I wrote the following function:
function ReplaceText($haystack,$needle){
$lastPos = 0;
$positions = array();
$rText = "";
while (($lastPos = strpos($haystack, $needle, $lastPos))!== false)
{
$positions[] = $lastPos;
if (substr($haystack, $lastPos-1, 1) == '.') {
// do nothing
} else {
$rText .= substr($text, 0, $lastPos).str_replace('\r\n', '', substr($text, $lastPos));
}
$lastPos = $lastPos + strlen($needle);
}
return $rText;
}
It's not working!
str_replace(".\r\n", '', $text)