Thi si probably a really simple thing to solve but I am failry new to PHP and cannot find the answer anywhere.

I have a search results page that calls data from a MYSQL database. All of the correct information is displaying but one of the fields contains text on different rows.

When the PHP displays the results all of the line breaks are removed. Is there a way of stopping this?

The current code I am using is:
<?php echo $row_jobdetails; ?>

Thanks

Member Avatar for rajarajan2017
<?php echo "\n".$row_jobdetails['job_description']; ?>
<?php echo "\n".$row_jobdetails['job_description']; ?>

Thank you for the quick reply - unfortunately the text is still all on the same line.

Member Avatar for rajarajan2017

What is the content reside in the description? you mean the text from the description is all having no link breaks? do you post your code?

You could always concantenate "<br />" to your 'job_description' field within the SQL statement. like this...

SELECT 
        job_id, 
        job_title, 
        job_description + '<br />' AS job_description
FROM tblTableName

...this way when your job_description field is displayed it will automatically break to the next line.

OR

<?php echo $row_jobdetails['job_description']; ?><br />

I'm not really a php man so the syntax may not be quite correct, but I think you're maybe looking for something like this...

<?php echo str_replace("\n","<br />",$row_jobdetails['job_description']); ?>
Member Avatar for muaazab

while($row_jobdetails = mysql_fetch_array($result)) {

echo $row_jobdetails;
echo "<br>";
}

but the line spaces as you would in phpMyAdmin

echo nl2br($row_jobdetails['job_description']);

The answer above is how I do it. The function nl2br() was created specifically for this sort of thing.

Hello,
Try using the nl2br(); function. It should help if I interpreted your question right. nl2br(); replaces newlines with <br /> tags.

nl2br($variable);

<pre>jnmvj
lkjgblknmjb,ljhv
,mjhnv</pre>
but it wont do text formatting

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.