Java Port, need php syn

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tgaugh
Forum Newbie
Posts: 3
Joined: Tue Jun 01, 2004 7:35 pm

Java Port, need php syn

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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);
?>
tgaugh
Forum Newbie
Posts: 3
Joined: Tue Jun 01, 2004 7:35 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

my code would do that... nl2br() .. as your JSP is reading up to a carriage return (last I checked)..
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post 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
tgaugh
Forum Newbie
Posts: 3
Joined: Tue Jun 01, 2004 7:35 pm

Post by tgaugh »

Thanks feyd, so new didn't realize it was a php cmd...read up. Excellent. Thank you again feyd.
Post Reply