RE: [PHP] Calling functions! Newbie problem!
| From: | Maxim Maletsky | Date: | Wed, 18 Oct 2000 08:12:10 +0000 |
| Subject: | RE: [PHP] Calling functions! Newbie problem! | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-20834@lists.php.net to get a copy of this message | ||
Correct me if I am wrong but I think I saw a new function in the latest PHP
4.0.3 called word_wrap()
is that what you are trying to do?
-----Original Message-----
From: Ivanoff Jari [mailto:Jari.Ivanoff@autonova.se]
Sent: Wednesday, October 18, 2000 4:56 PM
To: 'PHP'
Subject: [PHP] Calling functions! Newbie problem!
Well.. here we go again!
I have script that prints out some text from a database.
I have now found a function that does a wordwrap on the text.
I run my printout routine in a loop for 5 times to print out the 5 latest
entrys in the database.
I have declared the routine outside the loop.
I found the function in LinuxGurus
But how do I call the routine to handle the text?
I do not get any errormessage, but the "content" don't get printed.
It is for a newspage.
Here is my pretty lame attempt.
<?php
$string = $content;
$cols = 75;
$prefix = "";
function wrap_text ($string, $cols, $prefix) {
$t_lines = split( "\n", $string);
$outlines = "";
while(list($foo, $thisline) = each($t_lines))
{
if(strlen($thisline) > $cols)
{
$newline = "";
$t_l_lines = split(" ", $thisline);
while(list($bar, $thisword) = each($t_l_lines))
{
if((strlen($newline) + strlen($thisword)) > $cols)
{
$outlines .= $prefix.$newline."\n";
$newline = $thisword." ";
} else {
$newline .= $thisword." ";
} }
$outlines .= $prefix.$newline."\n";
} else {
$outlines .= $prefix.$thisline."\n";
} }
return $outlines;}
$db = mssql_connect("wsean1567","www","www")or die("Gick inte att
ansluta.");
mssql_select_db("VCU_Intranet",$db)or die("Kunde inte välja databas.");
$result = mssql_query("SELECT date,time,head,content,urgent FROM tbl_news
ORDER BY date DESC,time desc;")or die("Kunde inte utföra frågan.");
for ($count=0;$count <= 5;$count++)
{
$decide_color = mssql_result($result,$count,"urgent");
if ($decide_color > 0 )
{
$color = "#ff0000";
} else {
$color = "#000000";
}
$date = mssql_result($result,$count,"date");
printf("<font size =\"-2\">$date</font>\n");
$time = mssql_result($result,$count,"time");
printf("<font size =\"-2\">$time</font><br>\n");
$head = mssql_result($result,$count,"head");
printf("<font color = $color >$head</font><br>\n");
$content = mssql_result($result,$count,"content");
printf("$outlines");
}
?>
/Jari Ivanoff
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net