Page 1 of 1

Java Port, need php syn

Posted: Tue Jun 01, 2004 7:35 pm
by tgaugh
Can some of you guru's out there shed some light on this task in php?

Coming from mysql DB, have records with white space in there, hard returns. Is there a way in php to capture that whitespace for formatting?

I don't know the php code, this is what I am trying to port from (jsp) however:

<could not use php tags, as it is not php (sorry)>

<%
Clob cl = (Clob)data.get("article_x");
BufferedReader in = new BufferedReader(new InputStreamReader (cl.getAsciiStream()));
String str = null;
while((str = in.readLine()) != null)
{
out.println(str+"<br>");
}
%>

Short version of this is, how do I enter a hard break in html after returning my result set from mysql. Everywhere there is a break in the db I want to do in html, thus to kepp the formatting.

Thanks in advance....

tgaugh

Posted: Tue Jun 01, 2004 7:41 pm
by feyd
It's been a long time since I've done JSP so...

Code: Select all

<?php
mysql_connect($server,$username,$password) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());

$query = mysql_query("SELECT article FROM articles WHERE id = '2' LIMIT 1") or die(mysql_error());

if(mysql_num_rows($query) == 0)
  die("no article found.");

$result = mysql_fetch_row($query);
$result = $result[0];

echo nl2br($result);
?>

Posted: Tue Jun 01, 2004 7:56 pm
by tgaugh
I have the connection function is php already, here is the issues

the resultset reads

article1article2article3article4

When the db reads

article1
article2
article3
article4

So when the result is captured is prints the single line no breaks, I want to identify as I do in the jsp code above how to determine the "white space" and then enter manually a <br>

Does that help?

Thanks!!!

tgaugh

Posted: Tue Jun 01, 2004 8:49 pm
by feyd
my code would do that... nl2br() .. as your JSP is reading up to a carriage return (last I checked)..

Posted: Tue Jun 01, 2004 8:53 pm
by tim
if all else fails, it only takes one second to visit php.net and read up on the suggested command. as it would be a much easier way for you to acheive your wishes

http://www.php.net

Posted: Tue Jun 01, 2004 10:26 pm
by tgaugh
Thanks feyd, so new didn't realize it was a php cmd...read up. Excellent. Thank you again feyd.