Q1: See the script below Q2 : n/a Q3 : n/a
Q4 : You have to find the insertion point with strpos, and then insert like this $pos = strpos($mystring,$findme); if ($pos>0) { $leftmost = substr($mystring,0,$pos); $rightmost = substr($mystring,$pos,strlen($mystring)-$pos); $new_string = $leftmost . "XPTO" . $rightmost; } else $new_string = $mystring; The script <?php $mystring = 'foo foo foo test Foo FOO Foo fOO foo'; $x = 'test'; $pos = strpos($mystring,$x); echo "POS=$pos<br>"; $b = eregi_replace("foo","bar",$mystring); echo "A=$mystring<br>B=$b<br>"; $leftmost = substr($mystring,0,$pos); $rightmost = substr($mystring,$pos,strlen($mystring)-$pos); $new_string = $leftmost . "XPTO" . $rightmost; echo "NEW = $new_string"; ?> would result in POS=12 A=foo foo foo test Foo FOO Foo fOO foo B=bar bar bar test bar bar bar bar bar NEW = foo foo foo XPTOtest Foo FOO Foo fOO foo Does this help ? Luis ----- Original Message ----- From: "Bobo Wieland" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, July 25, 2003 12:21 PM Subject: [PHP-WIN] replacing strings... (hope it isn't too basic...) > Q1 :If I'm for example is going to replace all occurences of "foo" in the > following sentence with "bar" in case-insensetiv manner how would I do it? > > "Foo foo foo Foo fOO fOo" should be replaced with "Bar bar bar Bar bAR > bAr"... > > I guess I would need regular expressions? Right? > > ----------------- > Q2: I belive that there will be no cases with "fOO" or "fOo" only "Foo" or > "foo". > What I'm doing right now is a > > str_replace(strtolower("FOO"),uc_first(strtolower("BAR")),$myVar_str); > > This works okey most of the time, but the format from Q1 would be prefered. > Would I suffer a great deal of speed trying to fix the above output? > > ----------------- > Q3: Would it work to do a > > str_replace("foo","foobar","foo foo foo foo foo"); > > ----------------- > Q4: Is ther a predefined function for inserting a string into another string > at n characters? > > $myVar_str = "My bar string"; > str_insert("foo",$myVar_str, 3); > > would result in $myVar_str == My foobar string. > > I couldn't find this in the manual.... > > ----------------- > > > .b [EMAIL PROTECTED] > > > -- > PHP Windows Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP Windows Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php