Closed Thread Icon

Preserved Topic: forcing linebreak/wordwrap in php (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=18352" title="Pages that link to Preserved Topic: forcing linebreak/wordwrap in php (Page 1 of 1)" rel="nofollow" >Preserved Topic: forcing linebreak/wordwrap in php <span class="small">(Page 1 of 1)</span>\

 
frediko
Obsessive-Compulsive (I) Inmate

From: Haugesund, Norway
Insane since: Jul 2001

posted posted 07-18-2001 05:21

i found a function called wordwrap in php:

Example 1. wordwrap() example

$text = "The quick brown fox jumped over the lazy dog.";
$newtext = wordwrap( $text, 20 );
echo "$newtext\n";

output:
The quick brown fox
jumped over the lazy dog.

i need this to make sure that it's impossible to mess up my design with long variables...
is is possible to make this happen in like a html-page which is including another file? erh... like if i have greymatter/guestbook set up, and just want to put it in my page, can i set it up so it checks everything out before it is printed out on the page? damn, i'm really tired now, so i can't be making much sense...

i tried:
<div id="tekst1"><?
$text = "flooooooooooooooooooooooooooooood";
$newtext = wordwrap( $text, 20 );
echo "$newtext\n";
?></div>

what is wrong there? how do i best put up a site with a lot of different areas, like greymatter, polls, menus, graphicz ++ ? should i write it in shtml (with includes) or php??

[so many questions really...]

hope someone can atleast answer me some/share their experience to help me out here
[very good sign that you are reading this then... ]

frediko

ps: a test layout on how it'll kinda look: http://www.frediko.f2s.com/start.html (here i've used style="clip: rect(0px, 220px, 339px, 0px);" to solve the problem... but i'd rather have it fixed up so that it doesnt just hide the overflowing content...)

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 07-18-2001 15:57

Ok, your post was a bit rambly. Next time if you could number your questions it would make it much easier to answer them.

So, from what I go, you will want to include your files with PHP using either require, or include.

I don't see why what you wrote would not work. The included files should be parsed for PHP.

You can't use SSI because documents are only parsed once, either for PHP or for SSI, so you would have to pick one and stick with it.

happy hunting,

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 07-18-2001 16:09

I noticed your example:
$text = "The quick brown fox jumped over the lazy dog.";
$newtext = wordwrap( $text, 20 );
echo "$newtext\n";


But wouldn't this do the same thing:

$text = wordwrap("The quick brown fox jumped over the lazy dog.", 20);
echo($text);


I think wordwrap a PHP4 function, and I'm running an earlier version, so I can't test. But two lines with one variable might make it a little easier.

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 07-18-2001 16:36

<? echo wordwrap($text,20,"<br>") ; ?>

I believe that that would work as well. It would also give you the appearance of HTML line break. If you want even more formatting you might be inclinded to try.

<? echo wordwrap($text,20,"<br>\n"); ?>

Happy Hunting,

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 07-18-2001 17:25

By default, wordwrap() function wraps lines *betwen words* (it won't split one word if it is longer than width specified), so that's why your example Fediko, won't work. You have to call wordwrap() function like this:

wordwrap($text, 20, "\n", 1);

The last parameter ("1") is important.

BTW While we are talking about compact code, there's no need to specify "echo" if that's the only function inside one <?php?> block. You can write it like this:

<?=wordwrap($text, 20, "\n", 1)?>

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 07-18-2001 18:16

Okay, just out of curiosity, could you do this:

code:
<?=wordwrap("The quick brown fox jumped over the lazy dog", 20, "\n", 1)?>



This would eliminate the variable part, and get all of the code on one line. I'm just curious....

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 07-18-2001 18:21

Yes, you can do that.

frediko
Obsessive-Compulsive (I) Inmate

From: Haugesund, Norway
Insane since: Jul 2001

posted posted 07-19-2001 15:08

wow, thanx you ppl are the greatest!

still...

ok, i tried to add: <?=wordwrap("
in my header file for greymatter(that blog/log/journal-thingy),
and then: ", 20, "\n", 1)?>
in the footer file in greymatter...

-this did not work, is this because
a. greymatter is then using ssi and i can't use both ssi and php...
b. i need the greymatter index file to be php, for the <? ?> tag to work...
c. i wrote it wrong? (some scripts use <?php ?> instead of just <? ?>...

? tips?

question 2:
what is the difference between using require and include when parsing in php-files?

thx a lot for all your help

frediko

[the site in question--> http://home.no.net/frediko/launch.php <--under development]

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 07-19-2001 16:26

Ok, for the blog, you can not simply open a file and have it parsed. I would believe you to know this. You would first need to open the file pass the data to a variable as a string, and then parse it and then, rewrite it... or what not.

I would have the word wrap take effect before it is written to the datafile. That means that on submit, you traverse their entries and wordwrap them appropriatly then write them.

wordwrap() works on strings, so if you get you data into a string then you can work on it with little in the way of problems.

For you require() and include() problem.

frediko
Obsessive-Compulsive (I) Inmate

From: Haugesund, Norway
Insane since: Jul 2001

posted posted 07-19-2001 23:35

ok, i've come to settling with the good faith in myself as a blogwriter never to flood my own blog, and fixed the guestbook to do the wrappin... thaz about all

thank you for your help, and for helpin out a total beginner like moi!

laterz!

frediko
[http://home.no.net/frediko]

« BackwardsOnwards »

Show Forum Drop Down Menu