Calling functions! Newbie problem!

From: Date: Wed, 18 Oct 2000 07:55:36 +0000
Subject: Calling functions! Newbie problem!
Groups: php.general 
Request: Send a blank email to php-general+get-20831@lists.php.net to get a copy of this message
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

« previous php.general (#20831) next »