Jump to content

How to creat a line break in a look


Go to solution Solved by valandor,

Recommended Posts

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>

post-179690-0-43378600-1444732746_thumb.png

Link to comment
https://forums.phpfreaks.com/topic/298568-how-to-creat-a-line-break-in-a-look/
Share on other sites

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;
?>

  • Solution

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 by valandor
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.