Jump to content

Line breaks


Nightshade123

Recommended Posts

Please help.. this is driving me insane!

 

This

 

 echo "------------------------------------\nAUTOMATED RESPONSE\n------------------------------------\n\n

 

Returns the string with each "\n" appearing as a new line (correct).

 

I have the same string in my MySQL database, and am using these functions to retrieve it:

 

function db_query($qstring,$print=0) {
global $db_link;
return @mysql_query($qstring);
}

function db_result($qhandle,$row,$field) {
return @mysql_result($qhandle,$row,$field);
}

function GetSetting($strName)
{
$sql = "SELECT `Value` FROM `setting` WHERE `Status` = 'Open' AND `Name` = '".addslashes($strName)."'";	
$result=db_query($sql);

if (!$result) {
	trigger_error('DB ERROR - Error getting setting: '.db_error(), E_USER_ERROR);
	return false;
}
return db_result($result,0,'Value');
}

echo GetSetting('EmailFooter');

 

This returns the string with the line breaks appearing as "\n"

 

------------------------------------\nAUTOMATED RESPONSE\n------------------------------------\n\n

 

There's no "addslashes()" function or anything like that.. just some simple functions to retrieve data from the database. So why are my line breaks not showing as link breaks?

Link to comment
https://forums.phpfreaks.com/topic/164291-line-breaks/
Share on other sites

in SQLyog, did you physically type out the slash and "n"? because it probably doesn't convert those to new lines. on that note, you can always convert it afterward with PHP, but the best way is to insert it with the PHP MySQL functions so the new lines are actually in there

Link to comment
https://forums.phpfreaks.com/topic/164291-line-breaks/#findComment-866764
Share on other sites

If you were to do an insert via the mysql functions like so:

<?php
  $value =  "------------------------------------\nAUTOMATED RESPONSE\n------------------------------------\n\n";
  $sql = "INSERT INTO `setting` (`Name`,`Value`,`Status`) VALUES ('Test','".mysql_real_escape_string($value)."','Open')";
  mysql_query($sql) or die(mysql_error());
?>

it should store it as an actual new line character and not a \n

Link to comment
https://forums.phpfreaks.com/topic/164291-line-breaks/#findComment-866841
Share on other sites

You would need to convert the string into an external variable that you pass into the mysql insert. Placing it in directly as text through a database tool (such as phpMyAdmin) will treat it as a string and not parse the individual line breaks.

 

Brian

http://www.mvispy.com

New Developer API Released

Link to comment
https://forums.phpfreaks.com/topic/164291-line-breaks/#findComment-867068
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.