optimaximal Posted November 30, 2006 Share Posted November 30, 2006 Hiya all, first thread and all...Basically, I'm pulling data from my company's customer database (running on MSSQL - SQL Server) for the purpose of mailings in order to create a web-based printable label system (don't ask :)).The problem i'm facing is the SQL Server uses the CHAR(13) ASCII code (aka. a carriage return) and I need a way to grab this in PHP so that I can use the str_replace function to replace it with a form of carriage return that a web browser can understand (i.e. <br>).Here's the code -[code]$connection_string = 'DRIVER={SQL Server};SERVER=########;DATABASE=######';$user = '######';$pass = '######';$connection = odbc_connect( $connection_string, $user, $pass );$sqlquery="SELECT top 10 title, full_name, house, address, postcode, customer FROM cust ORDER BY NEWID();";$process=odbc_exec($connection, $sqlquery);//Finally, you extract all of the companies from the Customers table and display them onscreen in a list. Once the entire list has been displayed, the connection to the database is closed:while(odbc_fetch_row($process)){$Title = odbc_result($process, 1);$Name = odbc_result($process, 2);$House = odbc_result($process, 3);$Address = odbc_result($process, 4);//Replace Carriage Return$Address2 = str_replace("NEED THIS VALUE", "<br>", "$Address");$Postcode = odbc_result($process, 5);$custnum = odbc_result($process, 6);echo "<span class='small'>$custnum</span><p>$Title $Name<br>$House $Address2<br>$Postcode<p><hr>"; }odbc_close($connection);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/28989-extracting-replacing-the-sql-carriage-return-from-a-query/ 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.