<!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 document stored in a string</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="tidy.parsefile.html">tidy::parseFile</a></div> <div class="next" style="text-align: right; float: right;"><a href="tidy.repairfile.html">tidy::repairFile</a></div> <div class="up"><a href="class.tidy.html">tidy</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="tidy.parsestring" class="refentry"> <div class="refnamediv"> <h1 class="refname">tidy::parseString</h1> <h1 class="refname">tidy_parse_string</h1> <p class="verinfo">(PHP 5, PECL tidy >= 0.5.2)</p><p class="refpurpose"><span class="refname">tidy::parseString</span> -- <span class="refname">tidy_parse_string</span> — <span class="dc-title">Parse a document stored in a string</span></p> </div> <div class="refsect1 description" id="refsect1-tidy.parsestring-description"> <h3 class="title">Description</h3> <p class="para">Object oriented style</p> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><strong>tidy::parseString</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$input</code></span> [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$config</code></span> [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$encoding</code></span> ]] )</div> <p class="para rdfs-comment">Procedural style</p> <div class="methodsynopsis dc-description"> <span class="type"><a href="class.tidy.html" class="type tidy">tidy</a></span> <span class="methodname"><strong>tidy_parse_string</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$input</code></span> [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$config</code></span> [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$encoding</code></span> ]] )</div> <p class="para rdfs-comment"> Parses a document stored in a string. </p> </div> <div class="refsect1 parameters" id="refsect1-tidy.parsestring-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">input</code></em></span> <dd> <p class="para"> The data to be parsed. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">config</code></em></span> <dd> <p class="para"> The config <em><code class="parameter">config</code></em> can be passed either as an array or as a string. If a string is passed, it is interpreted as the name of the configuration file, otherwise, it is interpreted as the options themselves. </p> <p class="para"> For an explanation about each option, visit <a href="http://tidy.sourceforge.net/docs/quickref.html" class="link external">» http://tidy.sourceforge.net/docs/quickref.html</a>. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">encoding</code></em></span> <dd> <p class="para"> The <em><code class="parameter">encoding</code></em> parameter sets the encoding for input/output documents. The possible values for encoding are: <em>ascii</em>, <em>latin0</em>, <em>latin1</em>, <em>raw</em>, <em>utf8</em>, <em>iso2022</em>, <em>mac</em>, <em>win1252</em>, <em>ibm858</em>, <em>utf16</em>, <em>utf16le</em>, <em>utf16be</em>, <em>big5</em>, and <em>shiftjis</em>. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-tidy.parsestring-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns a new <a href="class.tidy.html" class="classname">tidy</a> instance. </p> </div> <div class="refsect1 examples" id="refsect1-tidy.parsestring-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-4056"> <p><strong>Example #1 <span class="function"><strong>tidy::parseString()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />ob_start</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?><br /></span><br /><html><br /> <head><br /> <title>test</title><br /> </head><br /> <body><br /> <p>error<br>another line</i><br /> </body><br /></html><br /><br /><span style="color: #0000BB"><?php<br /><br />$buffer </span><span style="color: #007700">= </span><span style="color: #0000BB">ob_get_clean</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$config </span><span style="color: #007700">= array(</span><span style="color: #DD0000">'indent' </span><span style="color: #007700">=> </span><span style="color: #0000BB">TRUE</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'output-xhtml' </span><span style="color: #007700">=> </span><span style="color: #0000BB">TRUE</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'wrap' </span><span style="color: #007700">=> </span><span style="color: #0000BB">200</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$tidy </span><span style="color: #007700">= </span><span style="color: #0000BB">tidy_parse_string</span><span style="color: #007700">(</span><span style="color: #0000BB">$buffer</span><span style="color: #007700">, </span><span style="color: #0000BB">$config</span><span style="color: #007700">, </span><span style="color: #DD0000">'UTF8'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$tidy</span><span style="color: #007700">-></span><span style="color: #0000BB">cleanRepair</span><span style="color: #007700">();<br />echo </span><span style="color: #0000BB">$tidy</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> test </title> </head> <body> <p> error<br /> another line </p> </body> </html> </pre></div> </div> </div> </p> </div> <div class="refsect1 notes" id="refsect1-tidy.parsestring-notes"> <h3 class="title">Notes</h3> <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">The optional parameters <em><code class="parameter">config</code></em> and <em><code class="parameter">encoding</code></em> were added in Tidy 2.0.</span></p></blockquote> </div> <div class="refsect1 seealso" id="refsect1-tidy.parsestring-seealso"> <h3 class="title">See Also</h3> <ul class="simplelist"> <li class="member"> <span class="function"><a href="tidy.parsefile.html" class="function" rel="rdfs-seeAlso">tidy::parseFile()</a> - Parse markup in file or URI</span></li> <li class="member"> <span class="function"><a href="tidy.repairfile.html" class="function" rel="rdfs-seeAlso">tidy::repairFile()</a> - Repair a file and return it as a string</span></li> <li class="member"> <span class="function"><a href="tidy.repairstring.html" class="function" rel="rdfs-seeAlso">tidy::repairString()</a> - Repair a string using an optionally provided configuration file</span></li> </ul> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="tidy.parsefile.html">tidy::parseFile</a></div> <div class="next" style="text-align: right; float: right;"><a href="tidy.repairfile.html">tidy::repairFile</a></div> <div class="up"><a href="class.tidy.html">tidy</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>