PHP helps

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
noriko94
Forum Newbie
Posts: 3
Joined: Sat May 02, 2009 11:20 pm

PHP helps

Post by noriko94 »

Could someone help me ?

Create a function that accepts four string variables and returns a string that contains an HTML table element, enclosing each of the variables in its own cell.
harlemblues
Forum Newbie
Posts: 3
Joined: Sat May 02, 2009 11:19 pm

Re: PHP helps

Post by harlemblues »

Actually it's very easy, maybe you just started with php.

By the way, here's the solution:

Code: Select all

function putInTable($s1,$s2,$s3,$s4){
    $table ="<table border=\"1\">" . 
            "<tr><td>" . $s1 . "</td></tr>" . 
            "<tr><td>" . $s2 . "</td></tr>" . 
            "<tr><td>" . $s3 . "</td></tr>" . 
            "<tr><td>" . $s4 . "</td></tr>" . 
         "</table>";
return $table;
}
Last edited by Benjamin on Fri May 08, 2009 9:29 pm, edited 1 time in total.
Reason: Changed code type from text to php.
mdk999
Forum Newbie
Posts: 22
Joined: Fri May 08, 2009 3:21 pm

Re: PHP helps

Post by mdk999 »

eh .. unless you really wanted a a function with 4 params .. I would recommend passing an array but .. you said string so here ya go ..

Code: Select all

 
 
function make_table($str1,$str2,$str3,$str4){
 
$table = <<<FO
 
<table>\r\n
<tr><td>{$str1}</td></tr>\r\n
<tr><td>{$str2}</td></tr>\r\n
<tr><td>{$str3}</td></tr>\r\n
<tr><td>{$str4}</td></tr>\r\n
</table>
FO;
 
return $table;
 
 
Last edited by Benjamin on Fri May 08, 2009 9:30 pm, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP helps

Post by requinix »

Well there goes the "we don't do your homework for you" policy...
Post Reply