...

View Full Version : code block and text wrapping



NancyJ
05-16-2008, 10:20 PM
I have a block of code that I'm using php's highlight_string to highlight nicely, php automatically wraps it in '<code>' tags, however some of the lines are quite quite long and they run outside the box, I'd like them to wrap like normal text but I can't seem to get it to do that.

rmedek
05-16-2008, 10:54 PM
Could you post code or a link to the page? <code> should wrap, unlike <pre>.

NancyJ
05-16-2008, 11:11 PM
<code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">$html</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">draw_list</span><span style="color: #007700">(</span><span style="color: #0000BB">$users</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">errors</span><span style="color: #007700">,</span><span style="color: #DD0000">"u"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">"id"</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"errors"</span><span style="color: #007700">));</span><span style="color: #0000BB">?&gt;</span>&nbsp;<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">$html</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">hidden_field</span><span style="color: #007700">(</span><span style="color: #DD0000">"users"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"id"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$users</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">id</span><span style="color: #007700">);</span><span style="color: #0000BB">?&gt;</span>&lt;br&nbsp;/&gt;

<br />&lt;label&nbsp;for&nbsp;=&nbsp;"users_username"&gt;Username&lt;/label&gt;&nbsp;<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">$html</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">text_field</span><span style="color: #007700">(</span><span style="color: #DD0000">"users"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"username"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$users</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">username</span><span style="color: #007700">);</span><span style="color: #0000BB">?&gt;</span>&lt;br&nbsp;/&gt;

<br />&lt;label&nbsp;for&nbsp;=&nbsp;"users_password"&gt;Password&lt;/label&gt;&nbsp;<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">$html</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">password_field</span><span style="color: #007700">(</span><span style="color: #DD0000">"users"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"password"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$_POST</span><span style="color: #007700">[</span><span style="color: #DD0000">'users'</span><span style="color: #007700">][</span><span style="color: #DD0000">'password'</span><span style="color: #007700">]);</span><span style="color: #0000BB">?&gt;</span>&lt;br&nbsp;/&gt;

<br />&lt;label&nbsp;for&nbsp;=&nbsp;"users_password"&gt;Confirm&nbsp;Password&lt;/label&gt;&nbsp;<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">$html</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">password_field</span><span style="color: #007700">(</span><span style="color: #DD0000">"users"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"password_confirm"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$users</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">password_confirm</span><span style="color: #007700">);</span><span style="color: #0000BB">?&gt;</span>&lt;br&nbsp;/&gt;

<br />&lt;label&nbsp;for&nbsp;=&nbsp;"users_email"&gt;Email&lt;/label&gt;&nbsp;<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">$html</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">text_field</span><span style="color: #007700">(</span><span style="color: #DD0000">"users"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"email"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$users</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">email</span><span style="color: #007700">);</span><span style="color: #0000BB">?&gt;</span>&lt;br&nbsp;/&gt;

<br />&lt;label&nbsp;for&nbsp;=&nbsp;"users_email_confirm"&gt;Confirm&nbsp;Email&lt;/label&gt;&nbsp;<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">$html</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">text_field</span><span style="color: #007700">(</span><span style="color: #DD0000">"users"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"email_confirm"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$users</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">email_confirm</span><span style="color: #007700">);</span><span style="color: #0000BB">?&gt;</span>&lt;br&nbsp;/&gt;

<br />&lt;input&nbsp;type&nbsp;=&nbsp;"submit"&nbsp;name&nbsp;=&nbsp;"submit"&nbsp;value&nbsp;=&nbsp;"Submit"&nbsp;/&gt;</span>
</code>

rmedek
05-16-2008, 11:27 PM
You're using &nbsp; to put spaces in between the words—non-breaking spaces. Change those to normal spaces and you'll be back on track.

oesxyl
05-17-2008, 12:17 AM
I have a block of code that I'm using php's highlight_string to highlight nicely, php automatically wraps it in '<code>' tags, however some of the lines are quite quite long and they run outside the box, I'd like them to wrap like normal text but I can't seem to get it to do that.
you can use pre with css white-space: normal. I don't think that spaces or entities are the problem, but I could be wrong. You also can try with code tag, but I don't use it, that's why I'm suggest pre( to make clear that I don't know if using pre is a better option then using code, :) ).

regards

NancyJ
05-17-2008, 12:25 AM
You're using &nbsp; to put spaces in between the words—non-breaking spaces. Change those to normal spaces and you'll be back on track.

I'm not putting them in. Its the highlight_string doing it.

rmedek
05-17-2008, 12:30 AM
I'm not putting them in. Its the highlight_string doing it.

It doesn't matter whose fault it is, a non-breaking space is just not going to break. Try this:

http://www.php.net/manual/en/function.highlight-string.php#73624

NancyJ
05-17-2008, 12:35 AM
I had to do a bit of preg replacement to get it to wrap right.



preg_replace('/&nbsp;([^&])/',' $1',highlight_string('code here',true));


Just replacing &nbsp; with spaces doesn't really work since multiple spaces show as a single space.

rmedek
05-17-2008, 12:36 AM
Glad you got it working.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum