document.write('<div class="php" style="font-family: monospace;">PHP<br />');
document.write('<br />');
document.write('<span style="color: #000000; font-weight: bold;">&lt;?</span><br />');
document.write('<span style="color: #000000; font-weight: bold;">function</span> how_many_lines<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$width</span>, <span style="color: #0000ff;">$string</span>, <span style="color: #0000ff;">$options</span> = <a target="_blank"&nbsp; href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!<a target="_blank"&nbsp; href="http://www.php.net/is_array"><span style="color: #000066;">is_array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$options</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #0000ff;">$options</span> = <a target="_blank"&nbsp; href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$width</span> &lt; <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <a target="_blank"&nbsp; href="http://www.php.net/trigger_error"><span style="color: #000066;">trigger_error</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">\'Width should be &gt; 0\'</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>;<br />');
document.write('&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('&nbsp; &nbsp; <span style="color: #0000ff;">$default_options</span> = <a target="_blank"&nbsp; href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><br />');
document.write('&nbsp; &nbsp; <span style="color: #ff0000;">\'white_spaces\'</span>&nbsp; &nbsp; &nbsp; =&gt; <a target="_blank"&nbsp; href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">\' \'</span>, <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #66cc66;">&#41;</span>,<br />');
document.write('&nbsp; &nbsp; <span style="color: #ff0000;">\'new_lines\'</span>&nbsp;&nbsp;=&gt; <a target="_blank"&nbsp; href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>,<br />');
document.write('&nbsp; &nbsp; <span style="color: #ff0000;">\'force_line_breaks\'</span> =&gt; <span style="color: #000000; font-weight: bold;">true</span>,<br />');
document.write('&nbsp; &nbsp; <span style="color: #ff0000;">\'callback\'</span>&nbsp; &nbsp; =&gt; <span style="color: #000000; font-weight: bold;">null</span>,<br />');
document.write('&nbsp; &nbsp; <span style="color: #ff0000;">\'callback_params\'</span>&nbsp; &nbsp;=&gt; <a target="_blank"&nbsp; href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>,<br />');
document.write('&nbsp; &nbsp; <span style="color: #ff0000;">\'char_widths\'</span>&nbsp; &nbsp; &nbsp; &nbsp;=&gt; <span style="color: #000000; font-weight: bold;">null</span>,<br />');
document.write('&nbsp; &nbsp; <span style="color: #66cc66;">&#41;</span>;<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; <a target="_blank"&nbsp; href="http://www.php.net/extract"><span style="color: #000066;">extract</span></a><span style="color: #66cc66;">&#40;</span><a target="_blank"&nbsp; href="http://www.php.net/array_merge"><span style="color: #000066;">array_merge</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$default_options</span>, <span style="color: #0000ff;">$options</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$callback</span> == <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$char_widths</span> != <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$callback</span> = <a target="_blank"&nbsp; href="http://www.php.net/create_function"><span style="color: #000066;">create_function</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">\'$char, $char_map\'</span>, <span style="color: #ff0000;">\'return (isset($char_map[$char]) ? $char_map[$char] : 0);\'</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$callback_params</span> = <a target="_blank"&nbsp; href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$char_widths</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$callback</span> = <a target="_blank"&nbsp; href="http://www.php.net/create_function"><span style="color: #000066;">create_function</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">\'$char\'</span>, <span style="color: #ff0000;">\'return 1;\'</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('<br />');
document.write('&nbsp; &nbsp; <span style="color: #0000ff;">$string</span> = <a target="_blank"&nbsp; href="http://www.php.net/str_replace"><span style="color: #000066;">str_replace</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$new_lines</span>, <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, <span style="color: #0000ff;">$string</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; <span style="color: #0000ff;">$string</span> = <a target="_blank"&nbsp; href="http://www.php.net/str_replace"><span style="color: #000066;">str_replace</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$white_spaces</span>, <span style="color: #ff0000;">\' \'</span>, <span style="color: #0000ff;">$string</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; <span style="color: #0000ff;">$str_length</span> = <a target="_blank"&nbsp; href="http://www.php.net/strlen"><span style="color: #000066;">strlen</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$string</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$str_length</span> &gt; <span style="color: #cc66cc;">0</span> &amp;&amp; <span style="color: #0000ff;">$string</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$str_length</span><span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">&#93;</span> == <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$str_length</span>--;<br />');
document.write('&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('<br />');
document.write('&nbsp; &nbsp; <span style="color: #0000ff;">$sep</span> = <span style="color: #cc66cc;">-1</span>;<br />');
document.write('&nbsp; &nbsp; <span style="color: #0000ff;">$pos</span> = <span style="color: #0000ff;">$j</span> = <span style="color: #0000ff;">$line_length</span> = <span style="color: #cc66cc;">0</span>;<br />');
document.write('&nbsp; &nbsp; <span style="color: #0000ff;">$number_of_lines</span> = <span style="color: #cc66cc;">1</span>;<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; <span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$pos</span> &lt; <span style="color: #0000ff;">$str_length</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$char</span> = <span style="color: #0000ff;">$string</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$pos</span><span style="color: #66cc66;">&#93;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$char</span> == <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$number_of_lines</span>++;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$pos</span>++;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$sep</span> = <span style="color: #cc66cc;">-1</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$j</span> = <span style="color: #0000ff;">$pos</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$line_length</span> = <span style="color: #cc66cc;">0</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$char</span> == <span style="color: #ff0000;">\' \'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$sep</span> = <span style="color: #0000ff;">$pos</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$line_length</span> += <a target="_blank"&nbsp; href="http://www.php.net/call_user_func_array"><span style="color: #000066;">call_user_func_array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$callback</span>, <a target="_blank"&nbsp; href="http://www.php.net/array_merge"><span style="color: #000066;">array_merge</span></a><span style="color: #66cc66;">&#40;</span><a target="_blank"&nbsp; href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$char</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #0000ff;">$callback_params</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$line_length</span> &gt; <span style="color: #0000ff;">$width</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$sep</span> == <span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!<span style="color: #0000ff;">$force_line_breaks</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$pos</span> == <span style="color: #0000ff;">$j</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">// да к тому же $pos == $j !</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$pos</span>++;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$pos</span> = <span style="color: #0000ff;">$sep</span> + <span style="color: #cc66cc;">1</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$sep</span> = <span style="color: #cc66cc;">-1</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$j</span> = <span style="color: #0000ff;">$pos</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$line_length</span> = <span style="color: #cc66cc;">0</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$number_of_lines</span>++;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$pos</span>++;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('<br />');
document.write('&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$number_of_lines</span>;<br />');
document.write('<span style="color: #66cc66;">&#125;</span><br />');
document.write('<span style="color: #000000; font-weight: bold;">?&gt;</span><br />');
document.write('<br />');
document.write('&nbsp;</div>');
document.write('<br />&nbsp;<br /><div style="font-size: 12px">Brought to you by the community at <a href="http://www.bytemycode.com/snippets/snippet/183/1/" target="_blank">byteMyCode</a>.</div>');
