Login

Username:


Password:


Remember me



Forgot Password?





 Merchandise




Table width with long links (split from Conversion thread)

Please post help requests in the Helpdesk forum. This forum is to be used for discussing the site, and events/projects.

Table width with long links (split from Conversion thread)

Postby Spack » Tue May 03, 2005 1:14 pm

Can anyone with good eyesight tell me why this page renders wider in IE than other forum pages?

Update: apparently it's the long links I posted. Even though the table is defined as 90% of the screen width, and link wrapping appears to happen, the renderers in IE and FireFox both make the table wider than I want it. So I have 2 solutions:

(1) Change the table back to a fixed width. I don't want to do this, as it means large gaps down the right for people on high resolutions, or tables going past the browser edge for low resolutions.

(2) Going through the post rendering code to get it to break long links and text without breaking the urls in the href themselves. Not sure if it's easy or not ...

I shall mull these over and may even find another workaround.
Last edited by Spack on Tue May 03, 2005 5:25 pm, edited 3 times in total.
User avatar
Spack
I R Ginger
Daemon Prince
 
Posts: 5476
Joined: Sat Feb 12, 2005 12:00 am
Location: Birmingham, UK
Blog: View Blog (6)

Postby Warmonger » Tue May 03, 2005 4:37 pm

I dunno, as I've noticed that IE in general has lousy display capabilities on most computers I use. It comes up looking "fatter." All the characters look bigger with less crispness to them, same for the pictures. I have yet to figure out how to change that, even though all the fonts are set to be the same and the same size.
40k: Black Templars, Tyranids, Dark Angels, Necrons, Iron Warriors, Eldar
BFG: Black Templars, Armageddon Fleet, Necrons, Chaos, Tyranids
WFB: Orcs&Goblins, Wood Elves, Chaos, Tomb Kings
User avatar
Warmonger
Warrior
Warrior
 
Posts: 63
Joined: Thu Mar 31, 2005 12:00 am
Location: North Western Arizona

Postby Spack » Tue May 03, 2005 5:02 pm

OK, I found some PHP code to do it, but I can't get it to work :(

Any PHP gurus want to tell me what's wrong with this? It just appears to spit back exactly what I put in.

Code: Select all
function mywordwrap($str, $max = 120, $break = '<br /> ') {
   
  // create array by deviding at each occurrence of "<a"
  $arr = explode('<a', $str);

  // break up long words in $arr[0] since
  // it will never contain a hyberlink
  $arr[0] = preg_replace('/([^\s]{'.$max.'})/i',"$1$break",$arr[0]);

  // run loop to devide remaining elements
  for($i = 1; $i < count($arr); $i++) {

   // devide each element in $arr at each occurrence of "</a>"
   $arr2 = explode('</a>', $arr[$i]);

   //MOD BY SPACK TO BREAK LINKED TEXT
   //split first part on >
   $arr3 = explode('>',$arr2[0]);
   //break up long link text which will be $arr3[1]
   $arr3[1] = preg_replace('/([^\s]{'.$max.'})/i',"$1$break",$arr3[1]);
   //rejoin to recreate $arr2[0]
   $arr2[0] = join('>',$arr3);
   //END MOD


   // break up long words in $arr2 that does not
   // contain hyberlinks
   $arr2[1] = preg_replace('/([^\s]{'.$max.'})/i',"$1$break",$arr2[1]);

   // rejoin $arr2 and assign as element in $arr
   $arr[$i] = join('</a>', $arr2);
  }
  // rejoin $arr to string and return it
  return join('<a', $arr);
}



Well, it seems to parse that code block ok, the lines starting with "break" are being broken by that function. Looks like it's just ignoring link text, which is exactly what I want it to break up :(

Update: Worked it out, it was ignoring the part I wanted to break on! Added a couple of additional lines to grab the linked text and break it, and it seems to work. Let me know if you notice any problems with it.

I'm pretty sure it's still a rendering bug - IE seems to use the pixel size of the text before applying it's style to links to work out how wide to render the table. And FireFox uses a slightly different font size, so the table is still a little wide, but at least it's a bit better than before (I could tweak for FF at 1024x by changing the break length, but is it really worth it?)

Dan
User avatar
Spack
I R Ginger
Daemon Prince
 
Posts: 5476
Joined: Sat Feb 12, 2005 12:00 am
Location: Birmingham, UK
Blog: View Blog (6)




Return to The Site



 Competitions



 Social Links