php hjælp

Her kan du få hjælp og stille spørgsmål til PHP!
Besvar
Mathias
Nørd
Nørd
Indlæg:145
Tilmeldt:5. apr 2012, 18:21
Kontakt:
php hjælp

Indlæg af Mathias » 30. aug 2012, 18:05

Hejsa jeg ville gerne have en textarea til at lave mellemrum altså fx

Test

Test

den bliver nemlig sendt sådan her :

test test

ville gerne have den sådan her

test

test

Kode :

Kode: Vælg alt

<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Forum Series - View Topic</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript">
function nl2br (str, is_xhtml) {
    var breakTag = '<br />';
    if (typeof is_xhtml != 'undefined' && !is_xhtml) {
        breakTag = '<br>';
    }
    return (str + '').replace(/([^>]?)\n/g, '$1'+ breakTag +'\n');
}
</script>
<style>
#div2 {
  -webkit-animation-name: rotateThis;
  -webkit-animation-duration:2s;
  -webkit-animation-iteration-count:infinite;
  -webkit-animation-timing-function:linear;
}
@-webkit-keyframes rotateThis {
  from {-webkit-transform:scale(0.5) rotate(0deg);}
  to {-webkit-transform:scale(0.5) rotate(360deg);}
} 
</style>
</head>
<div id="warper">
<div id="header">
<ul id="ulnav">    
<li id="linav"><a href="index.php" class="nav">Forside</a></li>
<li id="linav"><a href="http://dragonegcraft.dk/Forum/insert.php" class="nav">Opret dig som bruger</a></li>
</ul>
	</div>
    <div id="indhold">
  <?php
if (!isset($_SESSION['uid'])) {
	echo "<form action='login_parse.php' method='post'>
	Username: <input type='text' name='username' />&nbsp;
	Password: <input type='password' name='password' />&nbsp;
	<input type='submit' name='submit' value='Log In' />
	";
} else {
	echo "<p>You are logged is as ".$_SESSION['username']." &bull; <a href='logout_parse.php'>Logout</a>";
}
?>
<hr />
<div id="content">
<?php
include_once("connect.php");
$cid = $_GET['cid'];
$tid = $_GET['tid'];
$sql = "SELECT * FROM topics WHERE category_id='".$cid."' AND id='".$tid."' LIMIT 1";
$res = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($res) == 1) {
	echo "<table width='100%'>";
	if ($_SESSION['uid']) { echo "<tr><td colspan='2'><input type='submit' value='Opret indlæg i denne tråd' onClick=\"window.location = 'post_reply.php?cid=".$cid."&tid=".$tid."'\" /><hr />"; } else { echo "<tr><td colspan='2'><p>Please log in to add your reply.</p><hr /></td></tr>"; }
	while ($row = mysql_fetch_assoc($res)) {
		$sql2 = "SELECT * FROM posts WHERE category_id='".$cid."' AND topic_id='".$tid."'";
		$res2 = mysql_query($sql2) or die(mysql_error());
		while ($row2 = mysql_fetch_assoc($res2)) {
			echo "<tr><td valign='top' style='border: 1px solid #000000;'><div style='min-height: 125px;'>".$row['topic_title']."<br />by ".$row2['post_creator']." - ".$row2['post_date']."<hr />".$row2['post_content']."</div></td><td width='200' valign='top' align='center' style='border: 1px solid #000000;'>Bruger info her :<p></p><img src='Billed.png' width='64' height='80' /></td></tr><tr><td colspan='2'><hr /></td></tr>";
		}
		$old_views = $row['topic_views'];
		$new_views = $old_views + 1;
		$sql3 = "UPDATE topics SET topic_views='".$new_views."' WHERE category_id='".$cid."' AND id='".$tid."' LIMIT 1";
		$res3 = mysql_query($sql3) or die(mysql_error());
	}
} else {
	echo "<p>This topic does not exist.</p>";

}
?>
<?php $textAreaText = "This is a test\nThis is a test\nThis is a test";
echo $textAreaText;
echo "<br /><br />";
echo nl2br($testAreaText);?>
<div id="floatingCirclesG">
<div class="f_circleG" id="frotateG_01">
</div>
<div class="f_circleG" id="frotateG_02">
</div>
<div class="f_circleG" id="frotateG_03">
</div>
<div class="f_circleG" id="frotateG_04">
</div>
<div class="f_circleG" id="frotateG_05">
</div>
<div class="f_circleG" id="frotateG_06">
</div>
<div class="f_circleG" id="frotateG_07">
</div>
<div class="f_circleG" id="frotateG_08">
</div>
</div>
  </div>
    		<div id="foother">
              </div>
<body>
</body>
</html>

Brugeravatar
ThomasI
Grundlægger
Grundlægger
Indlæg:1528
Tilmeldt:28. dec 2010, 10:49

Re: php hjælp

Indlæg af ThomasI » 31. aug 2012, 08:46

Hej MAthias,

Når du skriver textarea, så mener du vist en variable ikke? At du gerne vil have mellemrum ind i variables værdi...

Næste gang må du gerne vælge det stykke af din kode ud som det drejer sig om...så tager det ikke så lang tid at kigge hele din kode igennem for at finde det område du spørger ind til...

Men går ud fra at vi snakker om din variable $textAreaText

Det ser udmmidelbart ud som om du er på rettet vej... med \n

Se evt her:

http://stackoverflow.com/questions/2726 ... breaks-php

Brugeravatar
scootergrisen
Moderator
Moderator
Indlæg:709
Tilmeldt:21. jun 2012, 23:40
Kontakt:

Re: php hjælp

Indlæg af scootergrisen » 31. aug 2012, 11:58

Jeg kan ikke se noget textarea tag i din kode.
Men prøv og ret :
$textAreaText = "This is a test\nThis is a test\nThis is a test";
til :
$textAreaText = "This is a test\r\nThis is a test\r\nThis is a test";

Mathias
Nørd
Nørd
Indlæg:145
Tilmeldt:5. apr 2012, 18:21
Kontakt:

Re: php hjælp

Indlæg af Mathias » 31. aug 2012, 12:11

Hej nej det er her hvor den bliver gemt.

Men vis man skal lave den i textarea koden så kan i se den her :

Kode: Vælg alt

<?php session_start(); ?>
<?php
if ((!isset($_SESSION['uid'])) || ($_GET['cid'] == "")) {
	header("Location: index.php");
	exit();
}
$cid = $_GET['cid'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Forum Series - Create Forum Topic</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>

<body>
<div id="warper">
<div id="header">
<ul id="ulnav">    
<li id="linav"><a href="index.php" class="nav">Forside</a></li>
<li id="linav"><a href="http://dragonegcraft.dk/Forum/insert.php" class="nav">Opret dig som bruger</a></li>
</ul>
	</div>
    <div id="indhold">
  <?php
echo "<p>You are logged is as ".$_SESSION['username']." &bull; <a href='logout_parse.php'>Logout</a>";
?>

<hr />
<div id="content">
<form action="create_topic_parse.php" method="post">
<p>Topic Title</p>
<input type="text" name="topic_title" size="98" maxlength="150" />
<p>Topic Content</p>
<textarea name="topic_content" rows="5" cols="75"></textarea>
<br /><br />
<input type="hidden" name="cid" value="<?php echo $cid; ?>" />
<input type="submit" name="topic_submit" value="Create Your Topic" />
</form>
  </div>
    		<div id="foother">
              </div>
</div>
</body>
</html>

Brugeravatar
scootergrisen
Moderator
Moderator
Indlæg:709
Tilmeldt:21. jun 2012, 23:40
Kontakt:

Re: php hjælp

Indlæg af scootergrisen » 31. aug 2012, 12:42

Okay men virker det ikke med mit forslag ?

Mathias
Nørd
Nørd
Indlæg:145
Tilmeldt:5. apr 2012, 18:21
Kontakt:

Re: php hjælp

Indlæg af Mathias » 31. aug 2012, 18:24

Ved jeg ikke har desvære ikke kigget på det ordenligt i nu kigger imorgen :D.

Ha en god dag.

Mvh Mathias

Besvar