note 86069 added to function.str-ireplace
| From: | info at daniel-marschall dot de | Date: | Wed, 01 Oct 2008 22:03:16 +0000 |
| Subject: | note 86069 added to function.str-ireplace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-144954@lists.php.net to get a copy of this message | ||
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?');
?>
----
Server IP: 69.147.83.197
Probable Submitter: 87.165.223.34
----
Manual Page -- http://www.php.net/manual/en/function.str-ireplace.php
Edit -- https://master.php.net/note/edit/86069
Del: integrated -- https://master.php.net/note/delete/86069/integrated
Del: useless -- https://master.php.net/note/delete/86069/useless
Del: bad code -- https://master.php.net/note/delete/86069/bad+code
Del: spam -- https://master.php.net/note/delete/86069/spam
Del: non-english -- https://master.php.net/note/delete/86069/non-english
Del: in docs -- https://master.php.net/note/delete/86069/in+docs
Del: other reasons-- https://master.php.net/note/delete/86069
Reject -- https://master.php.net/note/reject/86069
Search -- https://master.php.net/manage/user-notes.php