Boerboel649 Posted March 25, 2007 Share Posted March 25, 2007 Hi all, This should be a quick simple question. How do you start new lines in text in PHP? I thought I knew how but it's not working. It just puts it all on one line. Here's my code: <?php $_GET['id']; $query = mysql_query("SELECT fname, lname, nickname, number, position, height, weight, other FROM players WHERE id = '$id'"); while ($result = mysql_fetch_array($query)) { $fname = $result['fname']; $lname = $result['lname']; $nickname1 = $result['nickname']; $nickname2 = "\"$nickname1\""; $number = $result['number']; $position = $result['position']; $height = $result['height']; $weight = $result['weight']; $other = $result ['other']; $fullname = "$fname $nickname2 $lname"; echo "$fullname\n"; echo "$number\n"; echo "$position\n"; } ?> I would think that the \n would do it, but it's not! Thanks! Link to comment https://forums.phpfreaks.com/topic/44261-starting-new-line-in-text-in-php/ Share on other sites More sharing options...
edawg Posted March 25, 2007 Share Posted March 25, 2007 \n Link to comment https://forums.phpfreaks.com/topic/44261-starting-new-line-in-text-in-php/#findComment-214976 Share on other sites More sharing options...
Boerboel649 Posted March 25, 2007 Author Share Posted March 25, 2007 \n As you can see in my code, I tried that but it's not working! Link to comment https://forums.phpfreaks.com/topic/44261-starting-new-line-in-text-in-php/#findComment-214978 Share on other sites More sharing options...
podja Posted March 25, 2007 Share Posted March 25, 2007 Isnt it possible to use <br /> ? Link to comment https://forums.phpfreaks.com/topic/44261-starting-new-line-in-text-in-php/#findComment-214979 Share on other sites More sharing options...
Waldir Posted March 25, 2007 Share Posted March 25, 2007 \n would put it on a different line but wont show on your html try echo nl2br($fullname); echo nl2br($number); echo nl2br($position); maybe? Link to comment https://forums.phpfreaks.com/topic/44261-starting-new-line-in-text-in-php/#findComment-214980 Share on other sites More sharing options...
Boerboel649 Posted March 25, 2007 Author Share Posted March 25, 2007 Thanks! here's my final code to get that to work... <?php $_GET['id']; $query = mysql_query("SELECT fname, lname, nickname, number, position, height, weight, other FROM players WHERE id = '$id'"); while ($result = mysql_fetch_array($query)) { $fname = $result['fname']; $lname = $result['lname']; $nickname1 = $result['nickname']; $nickname2 = "\"$nickname1\""; $number = $result['number']; $position = $result['position']; $height = $result['height']; $weight = $result['weight']; $other = $result ['other']; $fullname = "$fname $nickname2 $lname"; echo nl2br("$fullname\n"); echo nl2br("$number\n"); echo nl2br("$position\n"); } ?> Link to comment https://forums.phpfreaks.com/topic/44261-starting-new-line-in-text-in-php/#findComment-214987 Share on other sites More sharing options...
Waldir Posted March 25, 2007 Share Posted March 25, 2007 looks good Link to comment https://forums.phpfreaks.com/topic/44261-starting-new-line-in-text-in-php/#findComment-214990 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.