Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP 

PHP Page Creation

I'm trying to make a mostly automated process.
So, that means making a PHP page from a template.
I've found out that it can create PHP pages using the function I have shown below, but with the template, it does not work.
(The variables at the top are just substitutes for values that would be gathered from the site)

PHP Code

<?php 
    $name 
= "math";
    
$category = "test";

    
$file = "/learn/math/test.php";
    
$handle = fopen($file, 'w');
    
$template = "    $mysqli = my information

        if (mysqli_connect_errno()) {
        printf(\"Contact the web administrator; there was a MySQLi connection failure: <br />\" . mysqli_connect_error());
        exit;
        }

        
$topics = $mysqli->query(\"SELECT * FROM `" . $name . "` WHERE `category` = '" . $category . "'\");

        if (!
$topics) {
        echo 
$mysqli->error;
        exit;
        }

        
$rows = $topics->num_rows;

        echo \"<p>\";

        for ( 
$i = 0; $i < $rows; $i++ ) {
        
$info = $topics->fetch_array();

        echo \"Category: \" . 
$info['category'] . \" -> <a href='http://www.mysticdev.com/learn/\" . $info['topic_name'] . \"/\" . $info['category'] . \"/\" . $info['filename'] . \"' title='\" . $title . \"'>\" . $info['title'] . \"</a> by: \" . $info['author'] . \" was created at \" . $info['date'] . \"<br />
        Preview: \" . 
$info['preview'] . \"<br /><br />\";
        }

        echo \"</p>\";

        mysqli_close(
$mysqli);";
    
fwrite($handle, $template);
    
fclose($handle); 
Better if you define what problem are you facing any errors thrown by function
There are none with that. However, if I try to escape the variables ($info['somevalue']), then I get an error. The reason I'd want these as a comment is that these are variables that need to be in the file itself. The error is:

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /home/mystic/public_html/learn/test.php on line 28

(Updated the original post with that code)
That script is a whole fail.

Just looking a the Syntax highlight explains how broken it is...
$template = " $mysqli = my information

What are you trying to do from that point on?
(Oct 17, 2013 07:45 AM)Charger Wrote:  $template = " $mysqli = my information

What are you trying to do from that point on?

Imagine you have a template for how a page looks. All I want to be able to do is create a new page (an actual .php page) when the script is run. It uses $name and $category to define where the script is on the server, and what the script's name is. The page that's created needs to have the variables and mysqli connection, but those are not to be affected by the creating of the new page. Because it's just a template.

The reason there is the backslash ( \ ) before most of the quotes ( " ) is so it doesn't try to use variables that don't exist in the script that makes the page. They exist on the actual page that's made.

(Oct 17, 2013 07:02 AM)MicroCoil Wrote:  That script is a whole fail.

Just looking a the Syntax highlight explains how broken it is...

Why don't you do something, instead of just looking. The syntax highlighting that the post shows is incorrect of what the actual highlighting is in the editor. So hop the fuck out, or be helpful.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[PHP] by MansonOct 8, 2017 01:55 PM 13 549 Oct 8, 2017 01:55 PM
Last Post: hoster1
[PHP] by StealthThraxNov 5, 2015 06:32 AM 7 168 Nov 5, 2015 06:32 AM
Last Post: StealthThrax
[PHP] by stuped200Aug 4, 2012 06:07 AM 5 195 Aug 4, 2012 06:07 AM
Last Post: stuped200