NancyJ
05-16-2008, 09: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, 09:54 PM
Could you post code or a link to the page? <code> should wrap, unlike <pre>.
NancyJ
05-16-2008, 10:11 PM
<code><span style="color: #000000">
<span style="color: #0000BB"><?php </span><span style="color: #007700">echo </span><span style="color: #0000BB">$html</span><span style="color: #007700">-></span><span style="color: #0000BB">draw_list</span><span style="color: #007700">(</span><span style="color: #0000BB">$users</span><span style="color: #007700">-></span><span style="color: #0000BB">errors</span><span style="color: #007700">,</span><span style="color: #DD0000">"u"</span><span style="color: #007700">, </span><span style="color: #DD0000">""</span><span style="color: #007700">, array(</span><span style="color: #DD0000">"id"</span><span style="color: #007700">=></span><span style="color: #DD0000">"errors"</span><span style="color: #007700">));</span><span style="color: #0000BB">?></span> <span style="color: #0000BB"><?php </span><span style="color: #007700">echo </span><span style="color: #0000BB">$html</span><span style="color: #007700">-></span><span style="color: #0000BB">hidden_field</span><span style="color: #007700">(</span><span style="color: #DD0000">"users"</span><span style="color: #007700">, </span><span style="color: #DD0000">"id"</span><span style="color: #007700">, </span><span style="color: #0000BB">$users</span><span style="color: #007700">-></span><span style="color: #0000BB">id</span><span style="color: #007700">);</span><span style="color: #0000BB">?></span><br />
<br /><label for = "users_username">Username</label> <span style="color: #0000BB"><?php </span><span style="color: #007700">echo </span><span style="color: #0000BB">$html</span><span style="color: #007700">-></span><span style="color: #0000BB">text_field</span><span style="color: #007700">(</span><span style="color: #DD0000">"users"</span><span style="color: #007700">, </span><span style="color: #DD0000">"username"</span><span style="color: #007700">, </span><span style="color: #0000BB">$users</span><span style="color: #007700">-></span><span style="color: #0000BB">username</span><span style="color: #007700">);</span><span style="color: #0000BB">?></span><br />
<br /><label for = "users_password">Password</label> <span style="color: #0000BB"><?php </span><span style="color: #007700">echo </span><span style="color: #0000BB">$html</span><span style="color: #007700">-></span><span style="color: #0000BB">password_field</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">$_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">?></span><br />
<br /><label for = "users_password">Confirm Password</label> <span style="color: #0000BB"><?php </span><span style="color: #007700">echo </span><span style="color: #0000BB">$html</span><span style="color: #007700">-></span><span style="color: #0000BB">password_field</span><span style="color: #007700">(</span><span style="color: #DD0000">"users"</span><span style="color: #007700">, </span><span style="color: #DD0000">"password_confirm"</span><span style="color: #007700">, </span><span style="color: #0000BB">$users</span><span style="color: #007700">-></span><span style="color: #0000BB">password_confirm</span><span style="color: #007700">);</span><span style="color: #0000BB">?></span><br />
<br /><label for = "users_email">Email</label> <span style="color: #0000BB"><?php </span><span style="color: #007700">echo </span><span style="color: #0000BB">$html</span><span style="color: #007700">-></span><span style="color: #0000BB">text_field</span><span style="color: #007700">(</span><span style="color: #DD0000">"users"</span><span style="color: #007700">, </span><span style="color: #DD0000">"email"</span><span style="color: #007700">, </span><span style="color: #0000BB">$users</span><span style="color: #007700">-></span><span style="color: #0000BB">email</span><span style="color: #007700">);</span><span style="color: #0000BB">?></span><br />
<br /><label for = "users_email_confirm">Confirm Email</label> <span style="color: #0000BB"><?php </span><span style="color: #007700">echo </span><span style="color: #0000BB">$html</span><span style="color: #007700">-></span><span style="color: #0000BB">text_field</span><span style="color: #007700">(</span><span style="color: #DD0000">"users"</span><span style="color: #007700">, </span><span style="color: #DD0000">"email_confirm"</span><span style="color: #007700">, </span><span style="color: #0000BB">$users</span><span style="color: #007700">-></span><span style="color: #0000BB">email_confirm</span><span style="color: #007700">);</span><span style="color: #0000BB">?></span><br />
<br /><input type = "submit" name = "submit" value = "Submit" /></span>
</code>
rmedek
05-16-2008, 10:27 PM
You're using to put spaces in between the words—non-breaking spaces. Change those to normal spaces and you'll be back on track.
oesxyl
05-16-2008, 11:17 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.
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-16-2008, 11:25 PM
You're using 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-16-2008, 11:30 PM
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-16-2008, 11:35 PM
I had to do a bit of preg replacement to get it to wrap right.
preg_replace('/ ([^&])/',' $1',highlight_string('code here',true));
Just replacing with spaces doesn't really work since multiple spaces show as a single space.