Click to See Complete Forum and Search --> : Containing double-quotes in var


aoeguy
12-21-2003, 07:39 AM
I need to have double-quotes in my variable start and inside the variable to parse other variables:


$news = "
<table border="0" cellpadding="0" cellspacing="0" width="100%" height="89" class="newscontent">
<tr>
<td width="40" class="newstitle" height="12">
<p><img border="0" width="40" height="40" src="<?php echo $dir,$img;?>"></p>
</td>
<td width="731" class="newstitle" height="12"><font face="arial" size="4">&nbsp;<?php echo "$title</font>";?></td>
<td width="40" class="newstitle" height="12">
<p><img border="0" src="<?php echo `$dir,$img`;?>" width="40" height="40"></p>
</td>
</tr>
<tr>
<td width="799" class height="57" colspan="3"><font face="Arial" size="1"><?php echo "&nbsp;
Posted on $date by $user";?></font>
<dl>
<dd>
<p><font face="Arial"><?php echo $text;?></font></dd>
</dl>
</td>
</tr>
<tr>
<td width="799" class height="25" colspan="3">
<p align="center"><a href="#top"><font color="#FFFFFF" face="Arial">Back
to Top</font></a></td>
</tr>
</table>



I know you cant have it like that, but it wont work with single-quotes. How can I change this, the HTML doesnt work properly if you change it there.

Then I need to have the variables written out so I can add them to the file I need to.

Please help :confused: :confused:

Bootsman123
12-21-2003, 08:35 AM
Use \" instead of ".

aoeguy
12-21-2003, 09:10 AM
On the start of the $news variable or inside it?

Pittimann
12-21-2003, 09:19 AM
Hi!

You will have to use them inside ($news="....\"....\"....";)
Cheers - Pit)

Bootsman123
12-21-2003, 10:02 AM
Originally posted by aoeguy
On the start of the $news variable or inside it?

Inside $news.

aoeguy
12-21-2003, 10:29 AM
Sure hope it will work :)
Thanks guys, if I have problems splitting the head section from the body in the destination page, I will be stuck :(

aoeguy
12-22-2003, 10:34 AM
:(

When I write the variable to the file I get no text or anything! It just adds the exact code not parsed :(
Here is my code now:


if ($_GET['mode'] == "view"){
#Check article
?>
<head>
<title>News Admin</title>
<LINK REL="StyleSheet" HREF="../aompage.css" TYPE="text/css">
</head>
<body background="../aom/bg/greek.jpg" topmargin="0" leftmargin="0" text="#FFFFFF">
<?php
$text = $_POST["text"];
$date = $_POST["date"];
$title = $_POST["title"];
$dir = $_POST["dir"];
$img = $_POST["img"];
$news = "
<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" height=\"89\" class=\"newscontent\">
<tr>
<td width=\"40\" class=\"newstitle\" height=\"12\">
<p><img border=\"0\" width=\"40\" height=\"40\" src=\"$dir$img\"></p>
</td>
<td width=\"731\" class=\"newstitle\" height=\"12\"><font face=\"arial\" size=\"4\">&nbsp;$title</font></td>
<td width=\"40\" class=\"newstitle\" height=\"12\">
<p><img border=\"0\" src=\"$dir$img\" width=\"40\" height=\"40\"></p>
</td>
</tr>
<tr>
<td width=\"799\" class height=\"57\" colspan=\"3\"><font face=\"Arial\" size=\"1\">
&nbsp;
Posted on $date by $user</font>
<dl>
<dd>
<p><font face=\"Arial\">$text</font></dd>
</dl>
</td>
</tr>
<tr>
<td width=\"799\" class height=\"25\" colspan=\"3\">
<p align=\"center\"><a href=\"#top\"><font color=\"#FFFFFF\" face=\"Arial\">Back
to Top</font></a></td>
</tr>
</table>
<p>&nbsp;</p>";

echo "$news";
echo "<a href=\"add.php?mode=add\">Add it</a>";
}
if ($_GET["mode"] == "add"){
#Add to news.php
echo ('Adding item to news.php...<br>Processing...');
$file = fopen ("../news.php",a);
fwrite($file, "$news");
rewind($file);
}
?>
<!-- EOF -->


I also tried the fwrite($file, "$news"); as fwrite($file, $news);

I could give you the whole file if you want, it has nearly the whole script in.

It shows (in news.php) just the table with no images and when I view source code its the exact doe thats here in the variable :confused:

Bootsman123
12-22-2003, 12:12 PM
Are you sure the variable is passed.

if ($_GET["mode"] == "add"){
#Add to news.php
echo ('Adding item to news.php...<br>Processing...');
$file = fopen ("../news.php",a);
fwrite($file, "$news");
rewind($file);
}

Echo $news within this function.

Pittimann
12-22-2003, 03:33 PM
Hi!

First of all: on the very top you are lacking the opening '<?php'.

The problem is not the mode=add, but the mode=view! This variable is not in the $_GET['']. The filling of the $news variable is depending on the condition:

if ($_GET['mode'] == "view"){
do stuff...
}

Due to the fact, that this is not available, all the code before the line

if ($_GET["mode"] == "add"){

will not be executed.

My assumption is, that the form submitting the data has a method="post" instead of "get"...

Cheers - Pit

aoeguy
12-25-2003, 11:33 AM
I had to fix it by just making it do that automatically when the page loads. That isnt the whole code there. It has got the php code tags in. I have a problem with the writing to the file:

I use list and explode then write the variables to the file I want to, but it removes the header from the file. If you need the file I can send it to you right away.