<!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>Reads a line</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.readline-write-history.html">readline_write_history</a></div> <div class="next" style="text-align: right; float: right;"><a href="refs.compression.html">Compression and Archive Extensions</a></div> <div class="up"><a href="ref.readline.html">Readline Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.readline" class="refentry"> <div class="refnamediv"> <h1 class="refname">readline</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">readline</span> — <span class="dc-title">Reads a line</span></p> </div> <div class="refsect1 description" id="refsect1-function.readline-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">string</span> <span class="methodname"><strong>readline</strong></span> ([ <span class="methodparam"><span class="type">string</span> <code class="parameter">$prompt</code></span> ] )</div> <p class="para rdfs-comment"> Reads a single line from the user. You must add this line to the history yourself using <span class="function"><a href="function.readline-add-history.html" class="function">readline_add_history()</a></span>. </p> </div> <div class="refsect1 parameters" id="refsect1-function.readline-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">prompt</code></em></span> <dd> <p class="para"> You may specify a string with which to prompt the user. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.readline-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns a single string from the user. The line returned has the ending newline removed. </p> </div> <div class="refsect1 examples" id="refsect1-function.readline-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-643"> <p><strong>Example #1 <span class="function"><strong>readline()</strong></span> Example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">//get 3 commands from user<br /></span><span style="color: #007700">for (</span><span style="color: #0000BB">$i</span><span style="color: #007700">=</span><span style="color: #0000BB">0</span><span style="color: #007700">; </span><span style="color: #0000BB">$i </span><span style="color: #007700">< </span><span style="color: #0000BB">3</span><span style="color: #007700">; </span><span style="color: #0000BB">$i</span><span style="color: #007700">++) {<br /> </span><span style="color: #0000BB">$line </span><span style="color: #007700">= </span><span style="color: #0000BB">readline</span><span style="color: #007700">(</span><span style="color: #DD0000">"Command: "</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">readline_add_history</span><span style="color: #007700">(</span><span style="color: #0000BB">$line</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #FF8000">//dump history<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">readline_list_history</span><span style="color: #007700">());<br /><br /></span><span style="color: #FF8000">//dump variables<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">readline_info</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.readline-write-history.html">readline_write_history</a></div> <div class="next" style="text-align: right; float: right;"><a href="refs.compression.html">Compression and Archive Extensions</a></div> <div class="up"><a href="ref.readline.html">Readline Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>