Jump to content


Splitting up bulk text


9 replies to this topic

#1 Lang

    Young Padawan

  • Members
  • Pip
  • 198 posts
  • Gender:Male
  • Location:Ontario, Canada

Posted 07 May 2006 - 04:58 PM

Ok, so someone posts a comment. Its along the lines of

"This is so COOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOL"

And completely destroys my beautiful page.

I've tried wordwrap(); didn't work. Does anyone know of a way I can split stupid things like that up?

Thanks in advance,

#2 DanWilliamson

    P2L Jedi

  • Members
  • PipPipPip
  • 650 posts

Posted 07 May 2006 - 05:24 PM

<?php

$string = "HERE IS THE TEXT";

$regex = "/([0-9]{0,2}:[0-9]{0,2})(STUFF HERE/";
$replace = "<br />$1$2";

$filter = preg_replace($regex, $replace, $string);

$entries = explode("<br />", $filter);
sort($entries);
unset($entries[0]);

foreach ($entries AS $entry)
	{
	echo $entry . "<br />";
	}

?>

I have no idea if this will work. I edited off somebody elses REGIX script, I do not understand it fully.

Edited by DanWilliamson, 07 May 2006 - 05:25 PM.


#3 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 07 May 2006 - 05:50 PM

Cant you just do something like
if(str_len($string) > 20){
$string = substr($string, 0, 18).'...';
}

if the word is longer than 20 charaters, it will strip it down to 18 characters and add 3 dots at the end.

Why didnt wordwrap work btw?
i think thats the ideal solution for this problem, i think this is what they made it for after all.

#4 Lang

    Young Padawan

  • Members
  • Pip
  • 198 posts
  • Gender:Male
  • Location:Ontario, Canada

Posted 07 May 2006 - 06:25 PM

View PostAvalanche, on May 7 2006, 06:50 PM, said:

Cant you just do something like
if(str_len($string) > 20){
$string = substr($string, 0, 18).'...';
}

if the word is longer than 20 charaters, it will strip it down to 18 characters and add 3 dots at the end.

Why didnt wordwrap work btw?
i think thats the ideal solution for this problem, i think this is what they made it for after all.

I have no idea why wordwrap didn't work =P If I knew that I would be finding an answer to it =P

And DanWilliamson, I tried that piece of code and it didn't work. Some comments didn't even show up.

[EDIT] I got the piece of code to work by removing unset($entries[0]);

I really don't know why that was there. But it got rid of the first entry in the array which seemed stupid.

Edited by Lang, 07 May 2006 - 07:00 PM.


#5 coolaid

    P2L Jedi Master

  • Members
  • PipPipPipPip
  • 1,435 posts
  • Gender:Male
  • Interests:i wonder..

Posted 07 May 2006 - 06:33 PM

show us the way you used wordwrap.

#6 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 08 May 2006 - 10:10 AM

hey, btw, cant you just use CSS so the column does not expand

<td style"table-layout:fixed;">

try that

#7 Lang

    Young Padawan

  • Members
  • Pip
  • 198 posts
  • Gender:Male
  • Location:Ontario, Canada

Posted 08 May 2006 - 04:03 PM

echo wordwrap($text, 150);

Thanks for that Avalanche, i'll try that too. If I used that it'd lower file size.

#8 coolaid

    P2L Jedi Master

  • Members
  • PipPipPipPip
  • 1,435 posts
  • Gender:Male
  • Interests:i wonder..

Posted 08 May 2006 - 05:34 PM

150 is too big, thats probably why

#9 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 09 May 2006 - 05:50 AM

i think you confused 150 pixels with 150 characters. :rolleyes:

#10 Lang

    Young Padawan

  • Members
  • Pip
  • 198 posts
  • Gender:Male
  • Location:Ontario, Canada

Posted 09 May 2006 - 03:27 PM

I didn't actually use 150. Its just a number I plugged in there.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users