Jump to content

Recommended Posts

Hi all.

 

I used to use php pretty regularly in my spare time, but that was years ago and it seems like I've lost all my pertinent knowledge, so I'm asking for some help here. Please. Pretty please.

 

I'm trying to make a php script that will speed up web page creation. The first page has several forms that pass data to the php script (name of the page, defining links, etc). I've remembered how to force php to insert HTML to a file, my current problem is that I need to insert some variables into the middle of the HTML repeatedly. ie: the file name occurs several times over the scope of the final webpage. I can't remember how to do this.

 

Do I end the php and start again every time I need to call a previously used variable? I'm lost. Here's my code:

 

 

<?php

 

$suite = $_POST['suite'] ;

$quad = $_POST['quad'] ;

$floor = $_POST['floor'] ;

$unit1 = $_POST['unit1'] ;

$unit2 = $_POST['unit2'] ;

$unit3 = $_POST['unit3'] ;

$unit4 = $_POST['unit4'] ;

$unit5 = $_POST['unit5'] ;

 

$filename = "$suite.html";

$fh = fopen($filename, 'w') or die("can't open file");

$input = '

 

<html>

<head>

<title>Paradise Village Office Park</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" >

<link rel="stylesheet" type="text/css" href="styles.css" >

</head>

<body>

<div id="doc" class="yui-t6">

<div id="hd">

<div id="header"><h1>

Paradise Village Office Park

<br/>

Plaza East Quadrant - Suite ';

 

 

//Here is where I want to include the '$suite' variable again before sending more html to the page

 

 

fwrite($fh, $input);

fclose($fh);

?>

Thanks for the reply!

 

When I insert it in double quotes it gives me an error:

Parse error: syntax error, unexpected T_STRING in /home/parse.php on line 55

 

When I end it with a semicolon it fails to write the variable to the file.  And when I include the variable in the fwrite, it makes the file but fails to write anything to it [ie:  fwrite($fh, $input, $suite);]

 

here's the code I used:

 

 

 

 

<?php

 

$suite = $_POST['suite'] ;

$quad = $_POST['quad'] ;

$floor = $_POST['floor'] ;

$unit1 = $_POST['unit1'] ;

$unit2 = $_POST['unit2'] ;

$unit3 = $_POST['unit3'] ;

$unit4 = $_POST['unit4'] ;

$unit5 = $_POST['unit5'] ;

 

$filename = "$suite.html";

$fh = fopen($filename, 'w') or die("can't open file");

$input = '

 

<html>

<head>

<title>Paradise Village Office Park</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" >

<link rel="stylesheet" type="text/css" href="styles.css" >

</head>

<body>

<div id="doc" class="yui-t6">

<div id="hd">

<div id="header"><h1>

Paradise Village Office Park

 

 

Plaza East Quadrant - Suite ';

 

 

"$suite"

 

 

fwrite($fh, $input);

fclose($fh);

?>

No no no.  Put the whole string in double quotes and escape all of the other ".  Or use sprintf() to get the values in.  Or use single quotes to concatenate like this:

 

$input = '<html>

<head>

<title>Paradise Village Office Park</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" >

<link rel="stylesheet" type="text/css" href="styles.css" >

</head>

<body>

<div id="doc" class="yui-t6">

<div id="hd">

<div id="header"><h1>

Paradise Village Office Park

 

 

Plaza East Quadrant - Suite

 

 

' . $suite ;

Worked like a champ, DarkWater.  Thank you very much for baby-stepping me through it.

 

One final question:

 

I'd like to add more html past that $suite variable.  Do I need the period and then the new variable?

 

ie:

 

$input = '<html>

<head>

<title>Paradise Village Office Park</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" >

<link rel="stylesheet" type="text/css" href="styles.css" >

</head>

<body>

<div id="doc" class="yui-t6">

<div id="hd">

<div id="header"><h1>

Paradise Village Office Park

 

 

Plaza East Quadrant - Suite

 

 

' . $suite .

 

$input2 = '<more html>' .;

Sasa, heredocs are ugly. D:  Anyway, do:

 

$input = '<html>

<head>

<title>Paradise Village Office Park</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" >

<link rel="stylesheet" type="text/css" href="styles.css" >

</head>

<body>

<div id="doc" class="yui-t6">

<div id="hd">

<div id="header"><h1>

Paradise Village Office Park

 

 

Plaza East Quadrant - Suite

 

 

' . $suite . 'some more HTML

<b>Blah blah blah</b>Lol';

You guys are champs.  I appreciate all the help.  DarkWater, your solution worked.  I've run into another snag with the new bit of code I'm trying to insert.  Is it because it's javascript?

 

<?php

 

  $suite = $_POST['suite'] ;

  $quad = $_POST['quad'] ;

  $floor = $_POST['floor'] ;

  $unit1 = $_POST['unit1'] ;

  $unit2 = $_POST['unit2'] ;

  $unit3 = $_POST['unit3'] ;

  $unit4 = $_POST['unit4'] ;

  $unit5 = $_POST['unit5'] ;

 

$filename = "$suite.html";

$fh = fopen($filename, 'w') or die("can't open file");

 

$input = '<html>

<head>

<title>Paradise Village Office Park</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" >

<link rel="stylesheet" type="text/css" href="styles.css" >

</head>

<body>

<div id="doc" class="yui-t6">

<div id="hd">

<div id="header"><h1>

Paradise Village Office Park

\<br>

Plaza East Quadrant - Suite ' . $suite . '

 

 

<br/>

Security Title

 

<script language="JavaScript">

nvval = "<ILONWEB FUNC=ShowValue type=text SYMBOL=NVE_TS_1101 size=10></ILONWEB>";    

if (nvval == "100.0 1"){

document.write('OCCUPIED');}

else{

document.write('UNOCCUPIED');}

</script>

 

</h1>

</div>

</div>

<div id="bd">

<div id="yui-main">

<div class="yui-b">

 

<div class="content"></br></a><img src="../../images/E-P111.jpg" width="500" height="418"></div>

 

</div>

</div>

<div class="yui-b">

<div id="secondary">

 

<form method="GET" action="

 

';

 

 

fwrite($fh, $input);

fclose($fh);

?>

Nope, New York. :D  Too bad I can't buy a beer for myself on your behalf.  Well actually there's this beer store in another town that supposedly does sell to minors (at least what I've heard) but whatever.  =P  Let's not get into that.

the ob_* functions would make this a lot easier. then you don't have to worry about escaping characters:

 

<?php
  $suite = $_POST['suite'] ;
  $quad = $_POST['quad'] ;
  $floor = $_POST['floor'] ;
  $unit1 = $_POST['unit1'] ;
  $unit2 = $_POST['unit2'] ;
  $unit3 = $_POST['unit3'] ;
  $unit4 = $_POST['unit4'] ;
  $unit5 = $_POST['unit5'] ;

  ob_start();
?>
<html>
<head>
<title>Paradise Village Office Park</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" >
<link rel="stylesheet" type="text/css" href="styles.css" >
</head>
<body>
<div id="doc" class="yui-t6">
<div id="hd">
<div id="header"><h1>
Paradise Village Office Park
\

Plaza East Quadrant - Suite <?php echo $suite; ?>




Security Title

<script language="JavaScript">
nvval = "<ILONWEB FUNC=ShowValue type=text SYMBOL=NVE_TS_1101 size=10></ILONWEB>";      
if (nvval == "100.0 1"){
document.write('OCCUPIED');}
else{
document.write('UNOCCUPIED');}
</script>
   
</h1>
</div>
</div>
<div id="bd">
<div id="yui-main">
<div class="yui-b">

<div class="content"></br>[/url]<img src="../../images/E-P111.jpg" width="500" height="418"></div>

</div>
</div>
<div class="yui-b">
<div id="secondary">
etc, etc,
<?php
  $input = ob_get_clean();

  $filename = "$suite.html";
  $fh = fopen($filename, 'w') or die("can't open file");
  fwrite($fh, $input);
  fclose($fh);
?>

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.