<!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>Parse a CSV string into an array</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.sscanf.html">sscanf</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.str-ireplace.html">str_ireplace</a></div> <div class="up"><a href="ref.strings.html">String Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.str-getcsv" class="refentry"> <div class="refnamediv"> <h1 class="refname">str_getcsv</h1> <p class="verinfo">(PHP 5 >= 5.3.0, PHP 7)</p><p class="refpurpose"><span class="refname">str_getcsv</span> — <span class="dc-title"> Parse a CSV string into an array </span></p> </div> <div class="refsect1 description" id="refsect1-function.str-getcsv-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">array</span> <span class="methodname"><strong>str_getcsv</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$input</code></span> [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$delimiter</code><span class="initializer"> = ","</span></span> [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$enclosure</code><span class="initializer"> = '"'</span></span> [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$escape</code><span class="initializer"> = "\\"</span></span> ]]] )</div> <p class="para rdfs-comment"> Parses a string input for fields in <acronym title="Comma Separated Value">CSV</acronym> format and returns an array containing the fields read. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> The locale settings are taken into account by this function. If <em>LC_CTYPE</em> is e.g. <em>en_US.UTF-8</em>, strings in one-byte encodings may be read wrongly by this function. </p> </p></blockquote> </div> <div class="refsect1 parameters" id="refsect1-function.str-getcsv-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <code class="parameter">input</code></dt> <dd> <p class="para"> The string to parse. </p> </dd> <dt> <code class="parameter">delimiter</code></dt> <dd> <p class="para"> Set the field delimiter (one character only). </p> </dd> <dt> <code class="parameter">enclosure</code></dt> <dd> <p class="para"> Set the field enclosure character (one character only). </p> </dd> <dt> <code class="parameter">escape</code></dt> <dd> <p class="para"> Set the escape character (one character only). Defaults as a backslash (<em>\</em>) </p> <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara"> Usually an <code class="parameter">enclosure</code> character is escaped inside a field by doubling it; however, the <code class="parameter">escape</code> character can be used as an alternative. So for the default parameter values <em>""</em> and <em>\"</em> have the same meaning. Other than allowing to escape the <code class="parameter">enclosure</code> character the <code class="parameter">escape</code> character has no special meaning; it isn't even meant to escape itself. </span> </p></blockquote> </dd> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.str-getcsv-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns an indexed array containing the fields read. </p> </div> <div class="refsect1 seealso" id="refsect1-function.str-getcsv-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><span class="function"><a href="function.fgetcsv.html" class="function" rel="rdfs-seeAlso">fgetcsv()</a> - Gets line from file pointer and parse for CSV fields</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.sscanf.html">sscanf</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.str-ireplace.html">str_ireplace</a></div> <div class="up"><a href="ref.strings.html">String Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>