Portrety Uliczne Nieznajomych - zobacz wyjątkową galerię portretów z warszawskich ulic
ZALOGUJ SIĘ
login:
hasło:
przypomnij hasło
załóż konto użytkownika
(i zobacz kilka porad gratis)
   
WYSZUKIWARKA I DZIAŁY
całe porady  tytuły
zaznacz działy do przeszukania
(brak wyboru = wszystkie działy)
PHP
MySQL >
PostgreSQL
SQLite
Perl
Java
XML
XSLT
XPath
WML
SVG
RegExp
Wyszukiwarki
Ochrona
VBScript
Google Plus
XHTML/CSS
JavaScript
Grafika
Flash
Photoshop
Windows
Linux
Bash
Apache
Procmail
E-biznes
Explorer
Opera
Firefox
Inne porady
   
KURSY, DOKUMENTACJE
Własne:
XHTML/CSS
JavaScript
ActionScript
WML, RSS, SSI
Pozostałe:
PHP
MySQL
Java API
więcej...
   
użytkowników online: 43
W CZYM MOGĘ POMÓC?


   
OPINIE UŻYTKOWNIKÓW
Uważam, że serwis jest najlepszy na świecie. Wykonany rzetelnie, a wszystkie skrypty sa dopracowane. Zamieszczony materiał godny mistrza. Jestem programistą od wielu lat i bez tego serwisu nie istnieje. Upraszacza życie każdemu programiście. Imponujący jest fakt, że do twórcy serwisu zawsze można się zwrócić z prośbą o pomoc i uzyskuje się ją w bardzo krótkim czasie. Najważniejsze w tym wszystkim jest to, że można korzystać z witryny za symboliczną opłatą.

Marcin Kowalski
Multinet Polska

   
GALERIA FOTOGRAFII
   
PODRĘCZNIK PHP 5.x, 4.x, 3.x - częściowo spolszczony / źródło: www.php.net

[Spis] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [X] [W] [Z]

str_ireplace

(PHP 5)

str_ireplace --  Case-insensitive version of str_replace().

Description

mixed str_ireplace ( mixed search, mixed replace, mixed subject [, int &count] )

This function returns a string or an array with all occurrences of search in subject (ignoring case) replaced with the given replace value. If you don't need fancy replacing rules, you should generally use this function instead of eregi_replace() or preg_replace() with the i modifier.

If subject is an array, then the search and replace is performed with every entry of subject, and the return value is an array as well.

If search and replace are arrays, then str_ireplace() takes a value from each array and uses them to do search and replace on subject. If replace has fewer values than search, then an empty string is used for the rest of replacement values. If search is an array and replace is a string; then this replacement string is used for every value of search.

Przykład 1. str_ireplace() example

<?php
$bodytag
= str_ireplace("%body%", "black", "<body text=%BODY%>");
?>

This function is binary safe.

Notatka: As of PHP 5.0.0 the number of matched and replaced needles will be returned in count which is passed by reference. Prior to PHP 5.0.0 this parameter is not available.

See also: str_replace(), ereg_replace(), preg_replace(), and strtr().




User Contributed Notes

tmad4000 at gmail dot com
18-Jan-2006 02:30

Here is a str_ireplace that works on servers running on lower than PHP 5 (4.4 is the lowest that it will work on, I think). If you want it to be non-case-sensitive, remove the strtolower commands from around $haystack and $needle.
<?php
//string insens_replace($haystack,$needle,$replacewith) - case insensitive replace function
function insens_replace($haystack,$needle,$replacewith)
{
   static
$recursed=FALSE;
   static
$beginpart='';
   static
$endpart='';

   if((
$pos=strpos(strtolower($haystack),strtolower($needle)))!==FALSE)
   {
      
$recursed=TRUE;
      
$beginpart.=substr($haystack,0,$pos).$replacewith;
      
$endpart=substr($haystack,$pos+strlen($needle));
       return
insens_replace($endpart,$needle,$replacewith);
   }
   else
   {
       if(
$recursed)
       {
          
$result=$beginpart.$endpart;
          
          
$recursed=FALSE;
          
$beginpart='';
          
$endpart='';
          
           return
$result;
       }
       else
       {
           return
$haystack;
       }
   }
}
?>


hfuecks at nospam dot org
04-Jul-2005 11:07

Note that character case is being defined by your server's locale setting, which effects strings containing non-ASCII characters.

See strtolower() - http://www.php.net/strtolower and comments - internally str_ireplace converts $search and $replace to lowercase to find matches.


daevid at daevid dot com
05-Apr-2005 10:14

here's a neat little function I whipped up to do HTML color coding of SQL strings.

<?php
/**
 * Output the HTML debugging string in color coded glory for a sql query
 * This is very nice for being able to see many SQL queries
 * @access    public
 * @return    void. prints HTML color coded string of the input $query.
 * @param    string $query The SQL query to be executed.
 * @author    Daevid Vincent [daevid@LockdownNetworks.com]
 *  @version    1.0
 * @date        04/05/05
 * @todo    highlight SQL functions.
 */
function SQL_DEBUG( $query )
{
   if(
$query == '' ) return 0;

   global
$SQL_INT;
   if( !isset(
$SQL_INT) ) $SQL_INT = 0;

  
//[dv] this has to come first or you will have goofy results later.
  
$query = preg_replace("/['\"]([^'\"]*)['\"]/i", "'<FONT COLOR='#FF6600'>$1</FONT>'", $query, -1);

  
$query = str_ireplace(
                           array (
                                  
'*',
                                  
'SELECT ',
                                  
'UPDATE ',
                                  
'DELETE ',
                                  
'INSERT ',
                                  
'INTO',
                                  
'VALUES',
                                  
'FROM',
                                  
'LEFT',
                                  
'JOIN',
                                  
'WHERE',
                                  
'LIMIT',
                                  
'ORDER BY',
                                  
'AND',
                                  
'OR ', //[dv] note the space. otherwise you match to 'COLOR' ;-)
                                  
'DESC',
                                  
'ASC',
                                  
'ON '
                                
),
                           array (
                                  
"<FONT COLOR='#FF6600'><B>*</B></FONT>",
                                  
"<FONT COLOR='#00AA00'><B>SELECT</B> </FONT>",
                                  
"<FONT COLOR='#00AA00'><B>UPDATE</B> </FONT>",
                                  
"<FONT COLOR='#00AA00'><B>DELETE</B> </FONT>",
                                  
"<FONT COLOR='#00AA00'><B>INSERT</B> </FONT>",
                                  
"<FONT COLOR='#00AA00'><B>INTO</B></FONT>",
                                  
"<FONT COLOR='#00AA00'><B>VALUES</B></FONT>",
                                  
"<FONT COLOR='#00AA00'><B>FROM</B></FONT>",
                                  
"<FONT COLOR='#00CC00'><B>LEFT</B></FONT>",
                                  
"<FONT COLOR='#00CC00'><B>JOIN</B></FONT>",
                                  
"<FONT COLOR='#00AA00'><B>WHERE</B></FONT>",
                                  
"<FONT COLOR='#AA0000'><B>LIMIT</B></FONT>",
                                  
"<FONT COLOR='#00AA00'><B>ORDER BY</B></FONT>",
                                  
"<FONT COLOR='#0000AA'><B>AND</B></FONT>",
                                  
"<FONT COLOR='#0000AA'><B>OR</B> </FONT>",
                                  
"<FONT COLOR='#0000AA'><B>DESC</B></FONT>",
                                  
"<FONT COLOR='#0000AA'><B>ASC</B></FONT>",
                                  
"<FONT COLOR='#00DD00'><B>ON</B> </FONT>"
                                
),
                          
$query
                        
);

   echo
"<FONT COLOR='#0000FF'><B>SQL[".$SQL_INT."]:</B> ".$query."<FONT COLOR='#FF0000'>;</FONT></FONT><BR>\n";

  
$SQL_INT++;

}
//SQL_DEBUG
?>


aidan at php dot net
21-Aug-2004 09:58

If you want to do string highlighting, for example highlighting search terms, try str_highlight().

http://aidan.dotgeek.org/lib/?file=function.str_highlight.php


aidan at php dot net
30-May-2004 07:36

This functionality is now implemented in the PEAR package PHP_Compat.

More information about using this function without upgrading your version of PHP can be found on the below link:

http://pear.php.net/package/PHP_Compat


 

 
  © 1996-2012 & Reporter.plmiejscao serwisieabonamentwarunki korzystaniaRSSkontakt