Jump to content

Recommended Posts

This gives me errors I cant make it one line how can i make multilin?

$content = ' <!doctype html>
<html>
<head>
<title>Zen Davis.com</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="style.css" type="text/css" rel="stylesheet" />

</head>

<body link="#5e6959" h3="#5e6959" vlink="#5e6959" >
<div class="content">
	<div class="top_block NavMenu">
		<div class="content">

		<!--Navigation line -->
		<h1 style="text-align:center" ><p><a href="index.php" style="text-decoration: none" >Home</a>&nbsp <a href="About.html" style="text-decoration: none" >About</a> &nbsp <a href="Contact.php" style="text-decoration: none" >Contact</a> &nbsp <a href="Games.php" style="text-decoration: none" size="25">Games</a></p></h1>

		</div>
	</div>
	<div class="top_block MiddlePhoto">
		<div class="content" style="text-align:center">
  Author: $author <br/>
  Date:  $date <br/>
  $body
  
		</div>


		</div>
	</div>
	<div class="top_block BottomTables">
		<div class="content">
		</div>
	</div>
</div>

</body>

</html>
';

Link to comment
https://forums.phpfreaks.com/topic/265431-multiline-variable/
Share on other sites

You need to state what error you are getting. I see nothing in that which would cause an error - but I'm positive it won't produce the results you are wanting.

 

You open the string with a single quote and close it with a single quote. Plus, there are no single quotes inside the string (if there were they would just need to be escaped). So, the string is properly defined. However inside the string I see what I assume are PHP variables:

Date:  $date <br/>

 

PHP variables are not interpreted inside single quoted strings, but they are within double quoted strings (there are also the nowdoc and heredoc methods of defining strings that work the same, respectively). You should read this page: http://php.net/manual/en/language.types.string.php especially the section about variable parsing: http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing

 

So, you can do a few different things:

 

1. Continue defining the string using single quotes. You would need to close/reopen the sting to append the variables such as:

$var = 'Date: ' . $date . '<br>';

 

2. Change the string to be defined by double quotes and do one of the following:

 

a. Escape all instances of double quotes inside the string

<div class=\"content\">

 

b. Change all instances of double quotes to single quotes inside the string

<div class='content'>

 

Many times you cannot do just a or just b, but have to use a combination of both. For example, if you were trying to display a measurement of 4 feet, 5 inches it should be displayed as follows: 4'5". So, you would have to escape which ever one was used to define the string. You can even mix and match different quotes for different parts of the strings. But, I think it's better to stick to one style - at least until you really understand it all and know why one method is better than another for a specific situation.

Link to comment
https://forums.phpfreaks.com/topic/265431-multiline-variable/#findComment-1360294
Share on other sites


<?php
$author=$_POST["author"];
$date=$_POST["date"];
$title=$_POST["title"];
$body=$_POST["body"];
$imagelink=$_POST["imgl"];
$con = mysql_connect("localhost","zendavis_tim","######");
if (!$con)
{
die('Could not connect: ' . mysql_error());
  }

mysql_select_db("zendavis_posts", $con);


mysql_query("INSERT INTO posts1 (author, imagelink,date,body,title)
VALUES ('$author', '$imagelink','$date','$body','$title')");
$title = str_replace(" ", "_", $title)
$content = ' <!doctype html>
<html>
<head>
<title>Zen Davis.com</title>
<meta http-equiv=\"Content-Type"\ content=\"text/html; charset=utf-8" \/>
<link href=\"style.css"\ type=\"text/css"\ rel=\"stylesheet"\ />

</head>

<body link=\"#5e6959"\ h3=\"#5e6959"\ vlink=\"#5e6959"\ >
<div class=\"content"\>
	<div class=\"top_block NavMenu"\>
		<div class=\"content"\>

		<!--Navigation line -->
		<h1 style=\"text-align:center"\ ><p><a href=\"index.php"\ style=\"text-decoration: none"\ >Home</a>&nbsp <a href=\"About.html"\ style=\"text-decoration: none"\ >About</a> &nbsp <a href=\"Contact.php"\ style=\"text-decoration: none"\ >Contact</a> &nbsp <a href=\"Games.php"\ style=\"text-decoration: none"\ size=\25"\>Games</a></p></h1>

		</div>
	</div>
	<div class=\"top_block MiddlePhoto"\>
		<div class=\"content"\ style=\"text-align:center"\>
  Author: '$author' <br/>
  Date:  '$date' <br/>
  '$body'
  
		</div>


		</div>
	</div>
	<div class=\"top_block BottomTables"\>
		<div class=\"content"\>
		</div>
	</div>
</div>

</body>

</html>
';
$file = "$title.html";
$open = fopen($file, "w");
fwrite($open, $content);
fclose($open);
header("Location: http://zendavis.com/$title.html");
?>

Link to comment
https://forums.phpfreaks.com/topic/265431-multiline-variable/#findComment-1360321
Share on other sites

Still Gives me erorrs:((((((



<?php
$author=$_POST["author"];
$date=$_POST["date"];
$title=$_POST["title"];
$body=$_POST["body"];
$imagelink=$_POST["imgl"];
$link = $title ;
$con = mysql_connect("localhost","zendavis_tim","sherlock11<>");
if (!$con)
{
die('Could not connect: ' . mysql_error());
  }

mysql_select_db("zendavis_posts", $con);


mysql_query("INSERT INTO posts1 (author, imagelink,date,body,title,link)
VALUES ('$author', '$imagelink','$date','$body','$title','$link')");


$title = str_replace(" ", "_", $title);
$conatent = ' <!doctype html>
<html>
<head>
<title>Zen Davis.com</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="style.css" type="text/css" rel="stylesheet" />

</head>

<body link="#5e6959" h3="#5e6959" vlink="#5e6959" >
<div class="content">
	<div class="top_block NavMenu">
		<div class="content">

		<!--Navigation line -->
		<h1><div style="text-align:center"><p><a href="Index.php" style="text-decoration: none" >Home</a>&nbsp <a href="About.html" style="text-decoration: none" >About</a> &nbsp <a href="Contact.php" style="text-decoration: none" >Contact</a> &nbsp <a href="Games.php" style="text-decoration: none" size="25">Games</a></p></div></h1>

		</div>
	</div>
	<div class="top_block MiddlePhoto">
		<div class="content">

		  Author:'$author; '<br/>
                  Date:  '$date;' <br/>
                 ' $body;'



		</div>
	</div>
	<div class="top_block BottomTables">
		<div class="content">
		</div>
	</div>
</div>
<!-- 
* Layout generated with http://layzilla.com
* Layout generator is free of use.
* We appreciate if you leave this comment block in commercial use of generator.
* All comment and ideas can be submitted to us using contacts below.
*
*    site: www.jmholding.com
*   email: info@jmholding.ru
*  twitter: @jmholding
-->
</body>

</html>
';
$file = "$title.html";
$open = fopen($file, "w");
fwrite($open, $conatent);
fclose($open);
header("Location: http://zendavis.com/$link.html");
?>

Link to comment
https://forums.phpfreaks.com/topic/265431-multiline-variable/#findComment-1360393
Share on other sites

.....

PHP variables are not interpreted inside single quoted strings, but they are within double quoted strings (there are also the nowdoc and heredoc methods of defining strings that work the same, respectively)........

 

So, you can do a few different things:

 

1. Continue defining the string using single quotes. You would need to close/reopen the sting to append the variables such as:

$var = 'Date: ' . $date . '<br>';

 

......

 

What part of # 1 you didn't understood?... are you even paying attention to what the people trying to helping you had wrote for you?... doesn't look like.

Link to comment
https://forums.phpfreaks.com/topic/265431-multiline-variable/#findComment-1360401
Share on other sites

Ok i got it one other thing i assighn the header at the end but it gives me this error

Warning: Cannot modify header information - headers already sent by (output started at /home/zendavis/public_html/insert.php:2) in /home/zendavis/public_html/insert.php on line 76?

Link to comment
https://forums.phpfreaks.com/topic/265431-multiline-variable/#findComment-1360443
Share on other sites

Did you read the manual for header?  I ask because the second line under the function description is:

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

Link to comment
https://forums.phpfreaks.com/topic/265431-multiline-variable/#findComment-1360461
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.