[PHP] Re: case-insensitive str_replace

2002-05-02 Thread J Smith


preg_replace() can be used with arrays.

J


Reuben D Budiardja wrote:

 
 Hi,
 I am in need of a case-insensitive str_replace. I've tried the search the
 archive and documentation, but the mostly suggested thing is to use
 eregi_replace. But this does not really solve the problem for me since the
 argument for eregi_replace can't be an array.
 
 The feature that I use in str_replace is to put the 'search' and 'replace'
 argument as an array, as described in the documentation for php = 4.0.5
 Some people suggested some functions in the archive and documentation, but
 I cannot find anything that can receive arrays as the arguments.
 
 So I am wondering if anyone has a function that is fully compatible with
 str_replace for php  4.0.5, but case-insensitive (something like
 stri_replace). I don't really want to reinvent the wheel here.
 
 Thanks in advance.
 Reuben D. Budiardja


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: case-insensitive str_replace

2002-05-02 Thread Reuben D Budiardja

On Thursday 02 May 2002 04:08 pm, J Smith wrote:
 preg_replace() can be used with arrays.

Yeah, but how to make it case-insensitive beside changing the my search and 
replace strings to a regular expression? The problem is that I have a big 
array for search and replace, and it would be most labourious to change them 
to reg exp.

There should be something simpler and more elegant to do this.

Thanks.
Rdb

 J

 Reuben D Budiardja wrote:
 
  The feature that I use in str_replace is to put the 'search' and
  'replace' argument as an array, as described in the documentation for php
  = 4.0.5 Some people suggested some functions in the archive and
  documentation, but I cannot find anything that can receive arrays as the
  arguments.
 
  So I am wondering if anyone has a function that is fully compatible with
  str_replace for php  4.0.5, but case-insensitive (something like
  stri_replace). I don't really want to reinvent the wheel here.
 
  Thanks in advance.
  Reuben D. Budiardja


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: case-insensitive str_replace

2002-05-02 Thread Mike Eheler

Well to make it case insensitive, you could change them to '/search/i'. 
Adding that /i makes them case-insensitive.

Mike

Reuben D Budiardja wrote:
 On Thursday 02 May 2002 04:08 pm, J Smith wrote:
 
preg_replace() can be used with arrays.

 
 Yeah, but how to make it case-insensitive beside changing the my search and 
 replace strings to a regular expression? The problem is that I have a big 
 array for search and replace, and it would be most labourious to change them 
 to reg exp.
 
 There should be something simpler and more elegant to do this.
 
 Thanks.
 Rdb
 
  J
 
Reuben D Budiardja wrote:

The feature that I use in str_replace is to put the 'search' and
'replace' argument as an array, as described in the documentation for php

= 4.0.5 Some people suggested some functions in the archive and

documentation, but I cannot find anything that can receive arrays as the
arguments.

So I am wondering if anyone has a function that is fully compatible with
str_replace for php  4.0.5, but case-insensitive (something like
stri_replace). I don't really want to reinvent the wheel here.

Thanks in advance.
Reuben D. Budiardja

 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: case-insensitive str_replace

2002-05-02 Thread CC Zona

In article [EMAIL PROTECTED],
 [EMAIL PROTECTED] (J Smith) wrote:

 Reuben D Budiardja wrote:
 
  I am in need of a case-insensitive str_replace.snip
  
  The feature that I use in str_replace is to put the 'search' and 'replace'
  argument as an array, as described in the documentation for php = 4.0.5
  Some people suggested some functions in the archive and documentation, but
  I cannot find anything that can receive arrays as the arguments.

 preg_replace() can be used with arrays.

Yes, just use the i (for case insensitive) modifier after the closing 
regex pattern delimiter:

$patterns=array(/foo/i,/bar/i);

-- 
CC

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: case-insensitive str_replace

2002-05-02 Thread CC Zona

In article [EMAIL PROTECTED],
 [EMAIL PROTECTED] (Reuben D Budiardja) wrote:

 On Thursday 02 May 2002 04:08 pm, J Smith wrote:
  preg_replace() can be used with arrays.
 
 Yeah, but how to make it case-insensitive beside changing the my search and 
 replace strings to a regular expression? The problem is that I have a big 
 array for search and replace, and it would be most labourious to change them 
 to reg exp.

It shouldn't be laborious, if the array's values were--as you 
implied--compatible with str_replace.  You're replacing an array of 
straight string values, correct?  So just escape the regex special values 
(preg_quotes()) in each while you're looping through the array to add the 
pattern delimiters and i modifier.  Then pass that array to preg_replace.

-- 
CC

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: case-insensitive str_replace

2002-05-02 Thread Philip Olson

This is a feature request, see:

  stri_replace() to compliment str_replace() :
  
  http://bugs.php.net/bug.php?id=5919

Regards,
Philip Olson


On Thu, 2 May 2002, CC Zona wrote:

 In article [EMAIL PROTECTED],
  [EMAIL PROTECTED] (Reuben D Budiardja) wrote:
 
  On Thursday 02 May 2002 04:08 pm, J Smith wrote:
   preg_replace() can be used with arrays.
  
  Yeah, but how to make it case-insensitive beside changing the my search and 
  replace strings to a regular expression? The problem is that I have a big 
  array for search and replace, and it would be most labourious to change them 
  to reg exp.
 
 It shouldn't be laborious, if the array's values were--as you 
 implied--compatible with str_replace.  You're replacing an array of 
 straight string values, correct?  So just escape the regex special values 
 (preg_quotes()) in each while you're looping through the array to add the 
 pattern delimiters and i modifier.  Then pass that array to preg_replace.
 
 -- 
 CC
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php