<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Function Overloading Feature</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mbstring.supported-encodings.html">Supported Character Encodings</a></div> <div class="next" style="text-align: right; float: right;"><a href="mbstring.php4.req.html">PHP Character Encoding Requirements</a></div> <div class="up"><a href="book.mbstring.html">Multibyte String</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="mbstring.overload" class="chapter"> <h1> Function Overloading Feature </h1> <p class="para"> You might often find it difficult to get an existing PHP application to work in a given multibyte environment. This happens because most PHP applications out there are written with the standard string functions such as <span class="function"><a href="function.substr.html" class="function">substr()</a></span>, which are known to not properly handle multibyte-encoded strings. </p> <p class="para"> mbstring supports a 'function overloading' feature which enables you to add multibyte awareness to such an application without code modification by overloading multibyte counterparts on the standard string functions. For example, <span class="function"><a href="function.mb-substr.html" class="function">mb_substr()</a></span> is called instead of <span class="function"><a href="function.substr.html" class="function">substr()</a></span> if function overloading is enabled. This feature makes it easy to port applications that only support single-byte encodings to a multibyte environment in many cases. </p> <p class="para"> To use function overloading, set <em>mbstring.func_overload</em> in <var class="filename">php.ini</var> to a positive value that represents a combination of bitmasks specifying the categories of functions to be overloaded. It should be set to 1 to overload the <span class="function"><a href="function.mail.html" class="function">mail()</a></span> function. 2 for string functions, 4 for regular expression functions. For example, if it is set to 7, mail, strings and regular expression functions will be overloaded. The list of overloaded functions are shown below. <table class="doctable table"> <caption><strong>Functions to be overloaded</strong></caption> <thead> <tr> <th>value of mbstring.func_overload</th> <th>original function</th> <th>overloaded function</th> </tr> </thead> <tbody class="tbody"> <tr> <td>1</td> <td> <span class="function"><a href="function.mail.html" class="function">mail()</a></span></td> <td> <span class="function"><a href="function.mb-send-mail.html" class="function">mb_send_mail()</a></span></td> </tr> <tr> <td>2</td> <td> <span class="function"><a href="function.strlen.html" class="function">strlen()</a></span></td> <td> <span class="function"><a href="function.mb-strlen.html" class="function">mb_strlen()</a></span></td> </tr> <tr> <td>2</td> <td> <span class="function"><a href="function.strpos.html" class="function">strpos()</a></span></td> <td> <span class="function"><a href="function.mb-strpos.html" class="function">mb_strpos()</a></span></td> </tr> <tr> <td>2</td> <td> <span class="function"><a href="function.strrpos.html" class="function">strrpos()</a></span></td> <td> <span class="function"><a href="function.mb-strrpos.html" class="function">mb_strrpos()</a></span></td> </tr> <tr> <td>2</td> <td> <span class="function"><a href="function.substr.html" class="function">substr()</a></span></td> <td> <span class="function"><a href="function.mb-substr.html" class="function">mb_substr()</a></span></td> </tr> <tr> <td>2</td> <td> <span class="function"><a href="function.strtolower.html" class="function">strtolower()</a></span></td> <td> <span class="function"><a href="function.mb-strtolower.html" class="function">mb_strtolower()</a></span></td> </tr> <tr> <td>2</td> <td> <span class="function"><a href="function.strtoupper.html" class="function">strtoupper()</a></span></td> <td> <span class="function"><a href="function.mb-strtoupper.html" class="function">mb_strtoupper()</a></span></td> </tr> <tr> <td>2</td> <td> <span class="function"><a href="function.stripos.html" class="function">stripos()</a></span></td> <td> <span class="function"><a href="function.mb-stripos.html" class="function">mb_stripos()</a></span></td> </tr> <tr> <td>2</td> <td> <span class="function"><a href="function.strripos.html" class="function">strripos()</a></span></td> <td> <span class="function"><a href="function.mb-strripos.html" class="function">mb_strripos()</a></span></td> </tr> <tr> <td>2</td> <td> <span class="function"><a href="function.strstr.html" class="function">strstr()</a></span></td> <td> <span class="function"><a href="function.mb-strstr.html" class="function">mb_strstr()</a></span></td> </tr> <tr> <td>2</td> <td> <span class="function"><a href="function.stristr.html" class="function">stristr()</a></span></td> <td> <span class="function"><a href="function.mb-stristr.html" class="function">mb_stristr()</a></span></td> </tr> <tr> <td>2</td> <td> <span class="function"><a href="function.strrchr.html" class="function">strrchr()</a></span></td> <td> <span class="function"><a href="function.mb-strrchr.html" class="function">mb_strrchr()</a></span></td> </tr> <tr> <td>2</td> <td> <span class="function"><a href="function.substr-count.html" class="function">substr_count()</a></span></td> <td> <span class="function"><a href="function.mb-substr-count.html" class="function">mb_substr_count()</a></span></td> </tr> <tr> <td>4</td> <td> <span class="function"><a href="function.ereg.html" class="function">ereg()</a></span></td> <td> <span class="function"><a href="function.mb-ereg.html" class="function">mb_ereg()</a></span></td> </tr> <tr> <td>4</td> <td> <span class="function"><a href="function.eregi.html" class="function">eregi()</a></span></td> <td> <span class="function"><a href="function.mb-eregi.html" class="function">mb_eregi()</a></span></td> </tr> <tr> <td>4</td> <td> <span class="function"><a href="function.ereg-replace.html" class="function">ereg_replace()</a></span></td> <td> <span class="function"><a href="function.mb-ereg-replace.html" class="function">mb_ereg_replace()</a></span></td> </tr> <tr> <td>4</td> <td> <span class="function"><a href="function.eregi-replace.html" class="function">eregi_replace()</a></span></td> <td> <span class="function"><a href="function.mb-eregi-replace.html" class="function">mb_eregi_replace()</a></span></td> </tr> <tr> <td>4</td> <td> <span class="function"><a href="function.split.html" class="function">split()</a></span></td> <td> <span class="function"><a href="function.mb-split.html" class="function">mb_split()</a></span></td> </tr> </tbody> </table> </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> It is not recommended to use the function overloading option in the per-directory context, because it's not confirmed yet to be stable enough in a production environment and may lead to undefined behaviour. </p> </p></blockquote> </div> <hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mbstring.supported-encodings.html">Supported Character Encodings</a></div> <div class="next" style="text-align: right; float: right;"><a href="mbstring.php4.req.html">PHP Character Encoding Requirements</a></div> <div class="up"><a href="book.mbstring.html">Multibyte String</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>