nicedad Posted October 13, 2015 Share Posted October 13, 2015 Hello everyone, Firstly, I'm not solving a home work or something like this, I'm just trying to fix a bug in code someone's written for me and hopfully I can fix it. I have column (Job Beschreibung) in a table, in which one need to write text. Unfortunately, the written text appears in one line without breaks so that one's to scroll horizontally (see attached image). anyone of any help and advice how to fix this issue. I attache the code also. <form method="post"> <div class="row space30"> <!-- row 2 begins --> <div class="col-md-12 text-center"> <?php $userCity = $objUser->getJobByLocation(); ?> <select name="search[location]" style="min-width: 150px;padding: 3px;margin-right:25px;"> <option value="">Kanton auswählen</option> <?php if(!empty($userCity)) { foreach($userCity as $k=>$v) { ?> <option value="<?php echo $userCity[$k]["location"]; ?>" <?php if($userCity[$k]["location"] == $location) { echo "selected"; } ?>><?php echo $userCity[$k]["location"]; ?></option> <?php } } ?> </select> <?php $userOccupation = $objUser->getQualification(); ?> <select name="search[Jqualify]" style="min-width: 150px;padding: 3px;"> <option value="">Beruf auswählen</option> <?php if(!empty($userOccupation)) { foreach($userOccupation as $k=>$v) { ?> <option value="<?php echo $userOccupation[$k]["Jqualify"]; ?>" <?php if($userOccupation[$k]["Jqualify"] == $Jqualify) { echo "selected"; } ?>><?php echo $userOccupation[$k]["Jqualify"]; ?></option> <?php } } ?> </select> <input type="submit" name="go" value="Search" style="border-color: none;border: 2px outset buttonface;padding: 2px 45px;margin-left: 20px;" > <input type="reset" value="Reset" style="border-color: none;border: 2px outset buttonface;padding: 2px 45px;margin-left: 10px;" onclick="window.location='jobs.php'"> </div> </div> <?php if(!empty($userList)) { ?> <div class="row space5"> <!-- row 3 begins --> <div class="col-md-12"> <table class="table table-striped"> <tr> <th style="width: 10%;">Firmenname</th> <th style="width: 10%;">Job Title</th> <th style="width: 10%;">Job Beschreibung</th> <th style="width: 10%;">Erfahrung</th> <th style="width: 10%;">Kanton</th> <th style="width: 10%;">Branche</th> <th style="width: 10%;">Job Type</th> <th style="width: 10%;">Qualifikation</th> <th style="width: 10%;">Vertragsart</th> <th style="width: 10%;">Gehalt/ Stunde</th></tr> <?php foreach($userList as $i => $value) { if(is_numeric($i)) { ?> <tr> <td><?php echo $userList[$i]["comp_name"]; ?></td> <td><?php echo $userList[$i]["jobtitle"]; ?></td> <td><?php echo $userList[$i]["job_description"]; ?></td> <td><?php echo $userList[$i]["minexp"]; ?> - <?php echo $userList[$i]["maxexp"]; ?></td> <td><?php echo $userList[$i]["location"]; ?></td> <td><?php echo $userList[$i]["Industry"]; ?></td> <td><?php echo $userList[$i]["Jtype"]; ?></td> <td><?php echo $userList[$i]["Jqualify"]; ?></td> <td><?php echo $userList[$i]["JContract"]; ?></td> <td><?php echo $userList[$i]["minsal"]; ?> - <?php echo $userList[$i]["maxsal"]; ?></td> </tr> <?php } }//for close ?> </table> </div> </div> <?php if(!empty($userList["perpage"])) { ?> <div class="pagination center"><?php echo $userList["perpage"]; ?></div> <?php } ?> <?php }//if close ?> </form> Quote Link to comment https://forums.phpfreaks.com/topic/298568-how-to-creat-a-line-break-in-a-look/ Share on other sites More sharing options...
Ch0cu3r Posted October 13, 2015 Share Posted October 13, 2015 Use nl2br <td><?php echo nl2br($userList[$i]["job_description"]); ?></td> Quote Link to comment https://forums.phpfreaks.com/topic/298568-how-to-creat-a-line-break-in-a-look/#findComment-1523152 Share on other sites More sharing options...
nicedad Posted October 13, 2015 Author Share Posted October 13, 2015 Hi Ch0cu3r, thanks so much for the replay. can you please advice where to add the line in my code? best, Quote Link to comment https://forums.phpfreaks.com/topic/298568-how-to-creat-a-line-break-in-a-look/#findComment-1523157 Share on other sites More sharing options...
nicedad Posted October 13, 2015 Author Share Posted October 13, 2015 I changed the line <?php echo $userList[$i]["job_description"]; ?> to the line td><?php echo nl2br($userList[$i]["job_description"]); ?></td> as per your advice, unfortunately didn't work. Quote Link to comment https://forums.phpfreaks.com/topic/298568-how-to-creat-a-line-break-in-a-look/#findComment-1523160 Share on other sites More sharing options...
boompa Posted October 13, 2015 Share Posted October 13, 2015 Use wordwrap on the output: https://secure.php.net/manual/en/function.wordwrap.php Quote Link to comment https://forums.phpfreaks.com/topic/298568-how-to-creat-a-line-break-in-a-look/#findComment-1523162 Share on other sites More sharing options...
nicedad Posted October 13, 2015 Author Share Posted October 13, 2015 Hello boompa, unfortunately didn't work either. as per your link, it should be a string in the function. I could know how to add this in your function. I inserted it in the function in the following way, is this right <?php $newtext = wordwrap($userList[$i]["job_description", 20, "<br />\n"); echo $newtext; ?> Quote Link to comment https://forums.phpfreaks.com/topic/298568-how-to-creat-a-line-break-in-a-look/#findComment-1523164 Share on other sites More sharing options...
ginerjm Posted October 13, 2015 Share Posted October 13, 2015 When you declare your table, add specific col widths to it so that the format isn't determined by the browser. Look up the <col> tag Quote Link to comment https://forums.phpfreaks.com/topic/298568-how-to-creat-a-line-break-in-a-look/#findComment-1523168 Share on other sites More sharing options...
cyberRobot Posted October 13, 2015 Share Posted October 13, 2015 I would imagine that you're not going to get too many entries where you'll get a series of letters without spaces. With that said, you could try the word-wrap property in CSS: https://developer.mozilla.org/en-US/docs/Web/CSS/word-wrap Quote Link to comment https://forums.phpfreaks.com/topic/298568-how-to-creat-a-line-break-in-a-look/#findComment-1523169 Share on other sites More sharing options...
nicedad Posted October 13, 2015 Author Share Posted October 13, 2015 for nothing guys, this is really strange Quote Link to comment https://forums.phpfreaks.com/topic/298568-how-to-creat-a-line-break-in-a-look/#findComment-1523174 Share on other sites More sharing options...
QuickOldCar Posted October 13, 2015 Share Posted October 13, 2015 Maybe you are seeing old results in browser? try clearing the browser cache. Quote Link to comment https://forums.phpfreaks.com/topic/298568-how-to-creat-a-line-break-in-a-look/#findComment-1523185 Share on other sites More sharing options...
ginerjm Posted October 13, 2015 Share Posted October 13, 2015 Strange? What happened when you set your column widths as I suggested? Quote Link to comment https://forums.phpfreaks.com/topic/298568-how-to-creat-a-line-break-in-a-look/#findComment-1523192 Share on other sites More sharing options...
Solution valandor Posted October 13, 2015 Solution Share Posted October 13, 2015 (edited) You can try using chunck_split() something like $string = chunk_split($string, '128', '<br />'); This worked on a large string I randomly generated. The reason that the nl2br() method doesn't work for you is because there are no new lines (\r\n) in your string. nl2br() converts those new line characters to <br /> tags. If there are going to be new lines in your text you can use the nl2br(). You can use the word-wrap function as well. If it's going to be one long word like all of your a's you would want to set the optional Boolean at the end to true to cut a word at the breaking point, otherwise it's going to wait till the end of the word to add the <br /> character into it... So in your case of all the A's it'll add it in after the last "a" doing a whole lot of nothing for you. Edited October 13, 2015 by valandor Quote Link to comment https://forums.phpfreaks.com/topic/298568-how-to-creat-a-line-break-in-a-look/#findComment-1523195 Share on other sites More sharing options...
nicedad Posted October 13, 2015 Author Share Posted October 13, 2015 Hi guys, problem solved, thanks a lot for all of you, as your adds were very helpful. Valando was right because my test text hadn't any break therefore was taken as one word. again thanks so much Quote Link to comment https://forums.phpfreaks.com/topic/298568-how-to-creat-a-line-break-in-a-look/#findComment-1523203 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.