petersro Posted December 8, 2008 Share Posted December 8, 2008 While working on the error handler i have an issue with it working but not putting things on a new line, any hints? // set the error reporting level for this script error_reporting(E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE); // Change defaults ini_set('display_errors', 'Off'); ini_set('log_errors', 'On'); // set to the user defined error handler set_error_handler("custom_err_handler"); // The path to the error log file define('ERROR_LOG_PATH', './logs/error_log.txt'); // Our custom error handler function function custom_err_handler($num, $str, $file, $line) { global $error_log_path; $err = ""; $err .= "---- PHP Error ----\n"; $err .= "Number: [" . $num . "]\n"; $err .= "String: [" . $str . "]\n"; $err .= "File: [" . $file . "]\n"; $err .= "Line: [" . $line . "]\n\n"; error_log($err, 3, ERROR_LOG_PATH); echo $err; } Quote Link to comment https://forums.phpfreaks.com/topic/136019-solved-php-echo-issue/ Share on other sites More sharing options...
flyhoney Posted December 8, 2008 Share Posted December 8, 2008 Try using "\r\n" instead of just "\n" Quote Link to comment https://forums.phpfreaks.com/topic/136019-solved-php-echo-issue/#findComment-709217 Share on other sites More sharing options...
petersro Posted December 8, 2008 Author Share Posted December 8, 2008 i tried the \r\n, it works on the logfile, but doesnt work on the php site, it still displays as normal Logfile output ---- PHP Error ---- Number: [2] String: [mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Access denied for user 'root'@'localhost' (using password: YES)] File: [C:\wamp\www\onepro\system\sys_mysql.php] Line: [12] ---- PHP Error ---- Number: [1024] String: [256] File: [C:\wamp\www\onepro\system\sys_mysql.php] Line: [12] ---- PHP Error ---- Number: [8] String: [use of undefined constant db_name - assumed 'db_name'] File: [C:\wamp\www\onepro\system\sys_mysql.php] Line: [13] ---- PHP Error ---- Number: [2] String: [mysql_select_db(): supplied argument is not a valid MySQL-Link resource] File: [C:\wamp\www\onepro\system\sys_mysql.php] Line: [13] ---- PHP Error ---- Number: [1024] String: [256] File: [C:\wamp\www\onepro\system\sys_mysql.php] Line: [13] Website display ---- PHP Error ---- Number: [2] String: [mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES)] File: [C:\wamp\www\onepro\system\sys_mysql.php] Line: [12] ---- PHP Error ---- Number: [1024] String: [256] File: [C:\wamp\www\onepro\system\sys_mysql.php] Line: [12] ---- PHP Error ---- Number: [8] String: [use of undefined constant db_name - assumed 'db_name'] File: [C:\wamp\www\onepro\system\sys_mysql.php] Line: [13] ---- PHP Error ---- Number: [2] String: [mysql_select_db(): supplied argument is not a valid MySQL-Link resource] File: [C:\wamp\www\onepro\system\sys_mysql.php] Line: [13] ---- PHP Error ---- Number: [1024] String: [256] File: [C:\wamp\www\onepro\system\sys_mysql.php] Line: [13] Quote Link to comment https://forums.phpfreaks.com/topic/136019-solved-php-echo-issue/#findComment-709232 Share on other sites More sharing options...
flyhoney Posted December 8, 2008 Share Posted December 8, 2008 Oh, yeah, if you want line breaks in a web page you have to use <br /> (see: nl2br) or wrap the text in <pre></pre> tags. Quote Link to comment https://forums.phpfreaks.com/topic/136019-solved-php-echo-issue/#findComment-709244 Share on other sites More sharing options...
petersro Posted December 8, 2008 Author Share Posted December 8, 2008 thanks mate working on introducing it in my code, i have another question, would make things more cleaner, is there a way i can when $db = mysql_select_db(db_name,$conn) or trigger_error(E_USER_ERROR); trigger_error(E_USER_ERROR) is reached, Is there a way to if there is a problem throw a custom error, secondly is there a way to get it to re-direct on error to say error.php on the root of the site, displaying the echo of whats wrong, in a clean html layout. im guessing the first is possable with a varable, but i dont know how to do the second part. Quote Link to comment https://forums.phpfreaks.com/topic/136019-solved-php-echo-issue/#findComment-709912 Share on other sites More sharing options...
DeanWhitehouse Posted December 8, 2008 Share Posted December 8, 2008 for custom error <?php $db = mysql_select_db(db_name,$conn); if(!$db) { echo "Customer error message"; //or if you want to redirect $error = "db error"; header("Location:error.php?error=".$error); } ?> then on error.php <?php if(isset($_GET['error'])) { echo $_GET['error']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/136019-solved-php-echo-issue/#findComment-709925 Share on other sites More sharing options...
petersro Posted December 8, 2008 Author Share Posted December 8, 2008 thanks man works a treat, however (i have been very suscessfull with customising the php error log) but it doesnt work, is there a simple way to when an arror is triggered, write it to a log file? Quote Link to comment https://forums.phpfreaks.com/topic/136019-solved-php-echo-issue/#findComment-709945 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.