Note Submitter: info at daniel-marschall dot de
----
If you want to keep the original capitalization when replacing some text, you can use this code I wrote:
<?php
function ext_str_ireplace($findme, $replacewith, $subject)
{
// Replaces $findme in $subject with $replacewith
// Ignores the case and do keep the original capitalization by using $1 in $replacewith
// Required: PHP 5
return substr($subject, 0, stripos($subject, $findme)).
str_replace('$1', substr($subject, stripos($subject, $findme), strlen($findme)), $replacewith).
substr($subject, stripos($subject, $findme)+strlen($findme));
}
?>
Example for using:
<?php
// Will print "RePlaCeMe" with red color, but after this it would be "replaceme", not "RePlaCeMe"
echo str_ireplace('replaceme', '<font color="#FF0000">$1</font>', 'Please RePlaCeMe, OK?');
// Will print "RePlaCeMe" with red color
echo ext_str_ireplace('replaceme', '<font color="#FF0000">$1</font>', 'Please RePlaCeMe, OK?');
?>
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.