wordwrap(); function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
duk
Forum Contributor
Posts: 199
Joined: Wed May 19, 2004 8:45 am
Location: London

wordwrap(); function

Post by duk »

hy,

i use wordwarp function to put a <br> tag, after 53 caracters, becouse i want that any post, that someones do, do not exceed, the limit of the html table...

but the problem is, that if i put 60 "g" caracters, works fine, but if i put 60 "f" caracters, will not work very fine...

my objective is format the text to not, expand the html table...

if i use

Code: Select all

<?php

echo "
<table border=1>
<td>hello</td>
</table>

";

?>
this appear a litle table, but if i put helllllllllllllllloooooooooooooooo, the table will expand, and i dont want this to happen, so i need to put a <br> tag, after x caracters, so the table will be with the width that i want... like post for foruns etc...

i use nl2br(); wordwrap(); and the htmlspecialcaracter(); functions, but i still have the problems...

anyone knows a good way to not permite that a html table expands, by having a lot of caracters ???

sorry my english
regards
duk
kevin7
Forum Commoner
Posts: 96
Joined: Fri May 21, 2004 6:54 am

Post by kevin7 »

hmm... i think php won't solve ur problem...

u can try to set the width of the table... or try put percentage...

<TABLE width=200>

or

<TABLE width=20%>

..... :wink:
duk
Forum Contributor
Posts: 199
Joined: Wed May 19, 2004 8:45 am
Location: London

Post by duk »

:( i make a fiew teste right now, the problem persists, the table expands, if i make this

<table border=1 width="10%">

<td>kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk</td>
</table>

but still, expands...

like all see the table from thsi forum, expands too LOL so i want to stop this to happen... anyone knows ???
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post by launchcode »

Here, I use this in my forum software - it should do what you want (but tailor the numbers to fit your page design)

Code: Select all

//	Proportional spaces check. For every 10 characters there should be 1 space
        if (substr_count($subject, " ") < floor(strlen($subject)/10)) { return 37; }
The Return just kicks back an error message - but you could use it to split the string up yourself.
duk
Forum Contributor
Posts: 199
Joined: Wed May 19, 2004 8:45 am
Location: London

Post by duk »

but this code will check if you have a space after 10 caracters, but if you dont have a space, he will put the space ???

is correct ??? if not, explain more this code pls :)
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Theres not much that you can do about it, its better to have it start a new line when there is a space so that you avoid splitting words up, but by counting so many letters will also work if you place "-" at the end of the line. You also need to make sure you do ive the table a true width such as 400, not 50%. You can also use css to ensure you dont excede, so have a play with that.
duk
Forum Contributor
Posts: 199
Joined: Wed May 19, 2004 8:45 am
Location: London

Post by duk »

so i can do anything very strange...

but about css, you have any example ??? a litle page with tuturials....

but i think i ill live the function wordwrap to put the <br> tag after x, caracters...
Post Reply