hi there....
i need some function tht gives me replacement of strings with out taking care of their case, i can't use str_ireplace (Case-insensitive version of str_replace()) because i hav't got php5 i have 4.1.1 right now . is there any replacement tht can help me out.
thanx.
Mannna.
string replace issue
Moderator: General Moderators
- shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
- Contact:
Code: Select all
$replaced = str_replace(strtolower($replace_this), $with_this, strtolower($in_this_string));include this in your code (before the use of str_ireplace is required):
Code: Select all
if (!function_exists('str_ireplace')) {
function str_ireplace($pat, $rep, $str)
{
if ((is_array($pat)) && (is_array($rep))) {
$c = count($pat);
for ($i = 0; $i < $c; $i++) {
$str = preg_replace('/' . preg_quote($pat[$i], '/') . '/i', $rep[$i], $str);
}
} elseif ((is_array($pat)) && (is_string($rep))) {
foreach ($pat as $p) {
$str = preg_replace('/' . preg_quote($p, '/') . '/i', $rep, $str);
}
} elseif ((is_string($pat)) && (is_string($rep))) {
$str = preg_replace('/' . preg_quote($pat, '/') . '/i', $rep, $str);
} else {
return false;
}
return $str;
}
}- itsmani1
- Forum Regular
- Posts: 791
- Joined: Mon Sep 29, 2003 2:26 am
- Location: Islamabad Pakistan
- Contact:
can any one help me in string padding i want to padd a string on both sides of string.
for example
i have a string =" This is my String";
now what i want is : to pass "_" on both sides of s and S
howz this possible....
?
for example
i have a string =" This is my String";
now what i want is : to pass "_" on both sides of s and S
howz this possible....
?
Last edited by itsmani1 on Mon Dec 05, 2005 12:40 am, edited 3 times in total.