Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts

    code block and text wrapping

    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.

  • #2
    Senior Coder
    Join Date
    Nov 2003
    Location
    Minneapolis, MN
    Posts
    2,879
    Thanks
    2
    Thanked 65 Times in 56 Posts
    Could you post code or a link to the page? <code> should wrap, unlike <pre>.

  • #3
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    Code:
    <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>
    Last edited by NancyJ; 05-16-2008 at 11:15 PM.

  • #4
    Senior Coder
    Join Date
    Nov 2003
    Location
    Minneapolis, MN
    Posts
    2,879
    Thanks
    2
    Thanked 65 Times in 56 Posts
    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.

  • #5
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by NancyJ View Post
    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

  • #6
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    Quote Originally Posted by rmedek View Post
    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.

  • #7
    Senior Coder
    Join Date
    Nov 2003
    Location
    Minneapolis, MN
    Posts
    2,879
    Thanks
    2
    Thanked 65 Times in 56 Posts
    Quote Originally Posted by NancyJ View Post
    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/functio...ring.php#73624
    Last edited by rmedek; 05-17-2008 at 12:34 AM.

  • #8
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    I had to do a bit of preg replacement to get it to wrap right.

    PHP Code:
    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.

  • #9
    Senior Coder
    Join Date
    Nov 2003
    Location
    Minneapolis, MN
    Posts
    2,879
    Thanks
    2
    Thanked 65 Times in 56 Posts
    Glad you got it working.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •