Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
I get the impression you aren't completely up to speed on what some of the code you used does.

die() is a function that causes script execution to stop immediately (hence the name) and has an optional argument which is output to the browser.

return is a keyword that causes a function to stop and return whatever comes afterwards.

In particular, the "return" in "return die()" is redundant because script execution will have stopped before the "returning" happens.

If you change return die($error); to return $error; then the function will return the contents of the variable $error, and your script will be able to continue to run.

Adbot
ADBOT LOVES YOU

Fluue
Jan 2, 2008

Hammerite posted:

I get the impression you aren't completely up to speed on what some of the code you used does.

die() is a function that causes script execution to stop immediately (hence the name) and has an optional argument which is output to the browser.

return is a keyword that causes a function to stop and return whatever comes afterwards.

In particular, the "return" in "return die()" is redundant because script execution will have stopped before the "returning" happens.

If you change return die($error); to return $error; then the function will return the contents of the variable $error, and your script will be able to continue to run.

Got it! Thanks for helping, the code works perfectly now.

wins32767
Mar 16, 2007

I have an issue where on one machine a require_once works fine, but on another it can't find the file. php.ini has one include_path, but the error message has a different one. As far as I can tell it's not being set in .htaccess files, so I'm at a bit of a loss. Any ideas as to where to look?

Masked Pumpkin
May 10, 2008

wins32767 posted:

I have an issue where on one machine a require_once works fine, but on another it can't find the file. php.ini has one include_path, but the error message has a different one. As far as I can tell it's not being set in .htaccess files, so I'm at a bit of a loss. Any ideas as to where to look?

It's an outside guess without seeing any code, but have you checked the permissions for the files on the server? If you just drop the file in the same directory as the script (and change the path appropriately), can you see it then?

wins32767
Mar 16, 2007

Masked Pumpkin posted:

It's an outside guess without seeing any code, but have you checked the permissions for the files on the server? If you just drop the file in the same directory as the script (and change the path appropriately), can you see it then?

It ended up being several nested problems. I'd already fixed the permissions error, but because the second error (the lack of an installed library) wasn't causing any error messages to be generated and I wasn't looking carefully at timestamps I failed to notice it. Tracking down the problem with the lack of installed library was quite a problem with no error messages let me tell you.

DholmbladRU
May 4, 2006
first off, I am very new to PHP and web programing so I do not have a great understading of the language. With that said I am trying to create a "user profile" page which will display certain infromation about users that is pulled from a Mysql database, the information will be mainly text based with one link to a image that is stored in an "user images" folder alongside the php source.

Would it be best to just use php/css, or could xml be used?

basically it would be something like this

https://wi.somethingawful.com/f3/f3ffc251e5cff56113348a19ee965e28b2ab688c.jpg

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

DholmbladRU posted:

first off, I am very new to PHP and web programing so I do not have a great understading of the language. With that said I am trying to create a "user profile" page which will display certain infromation about users that is pulled from a Mysql database, the information will be mainly text based with one link to a image that is stored in an "user images" folder alongside the php source.

Would it be best to just use php/css, or could xml be used?

basically it would be something like this

https://wi.somethingawful.com/f3/f3ffc251e5cff56113348a19ee965e28b2ab688c.jpg

You want to use HTML / CSS for display, and have PHP populate the dynamic bits. You *could* use XML ( and XSLT to render to the browser ) but you probably don't want to do that unless you have very good reasons not to just use HTML/CSS for display.

code:
<?php
 // code that gets the user info, and
 // assigns it to a '$user' object....
?>

<div class="userInfoWrapper">
 <img src="/images/userImages/<?php echo $user->imageName;?>" class="userImage" />
 <p class="userInfo"><?php echo $user->name;</p>
 [ spit out the rest of your info ]
</div>

DholmbladRU
May 4, 2006
I guess the only reason I thought XML might be applicable is that there will be ~ "profiles" to be displayed.

thanks for the information!

If I create a class "users" and am trying to store multiple entrys into that, would this be stored as an array

DholmbladRU fucked around with this message at 16:58 on May 21, 2010

Begby
Apr 7, 2005

Light saber? Check. Black boots? Check. Codpiece? Check. He's more machine than kid now.

DholmbladRU posted:

I guess the only reason I thought XML might be applicable is that there will be ~ "profiles" to be displayed.

thanks for the information!

If I create a class "users" and am trying to store multiple entrys into that, would this be stored as an array

You would create an array and add multiple users to it

php:
<?

class User
{
  var name;
}

$user1 = new User();
$user1->name = "fred";

$user2 = new User();
$user2->name = "george";

$users = array();
$users[] = $user1;
$users[] = $user2;

// Then to loop through your array, do something like this
foreach ($users as $user)
{
  echo $user->name . "<br />\n";
}

// The output would be
// fred<br />
// george<br />
?>

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Begby posted:

You would create an array and add multiple users to it

In addition to this, if you are pulling user info from a DB, you loop through the results in a similar manner:

php:
<?
// database connection stuff goes here
$queryResults = mysql_query('SELECT firstName, lastName FROM users WHERE 1'); //you'd write a better query

while( $user = mysql_fetch_object( $queryResults ) )
{
  printf("%s %s<br />\n", $user->firstName, $user->lastName);
}
?>
This would loop through the user data you returned from your query the same way Begby's example looped through an array you constructed manually.

DholmbladRU
May 4, 2006
thanks for all of the help guys. For defining var in a class does it need to be 'var $Fname'? It doesnt seen to like it when there is no '$' there.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

DholmbladRU posted:

thanks for all of the help guys. For defining var in a class does it need to be 'var $Fname'? It doesnt seen to like it when there is no '$' there.

http://www.php.net/manual/en/language.variables.basics.php

http://www.php.net/manual/en/getting-started.php

Jick Magger
Dec 27, 2005
Grimey Drawer
I need help picking out an MVC framework to use for a project. I'm helping an open source project convert their web gui from the mess that it is to something more manageable. I've got experience with MachII (coldfusion framework) but no experience with any for php.

suggestions?

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Jick Magger posted:

I need help picking out an MVC framework to use for a project. I'm helping an open source project convert their web gui from the mess that it is to something more manageable. I've got experience with MachII (coldfusion framework) but no experience with any for php.

suggestions?

Kohana or Zend. Ignore anyone who says Smarty.

Sab669
Sep 24, 2009

So I'm pretty new to PHP, having a rudimentary problem simply passing data page 1 form to another.

http://pastebin.com/tJhivGzK

That's the code I have, basically just trying to make a little thumbnail sort of page. Then when you click the thumbnail it takes you to a full blown image. How ever, the only way I've ever passed data before is with a form, so I'm not sure how I go about doing it through hyperlinks? Not really sure where to go from here...

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Sab669 posted:

So I'm pretty new to PHP, having a rudimentary problem simply passing data page 1 form to another.

http://pastebin.com/tJhivGzK

That's the code I have, basically just trying to make a little thumbnail sort of page. Then when you click the thumbnail it takes you to a full blown image. How ever, the only way I've ever passed data before is with a form, so I'm not sure how I go about doing it through hyperlinks? Not really sure where to go from here...

If you use the GET method to pass information to a page (as in page.php?PhotoID=12345) then the information is found in the $_GET array and can be retrieved in the same way as the information in the $_POST array (which you are presumably familiar with if you have dealt with forms).

Masked Pumpkin
May 10, 2008
It probably doesn't even need to be said, but I assume you're validating your inputs, right? $var = htmlentities($var, ENT_QUOTES) works pretty well for me, but if there are better options available, I'd be interested in hearing them.

Sab669
Sep 24, 2009

Hammerite posted:

If you use the GET method to pass information to a page (as in page.php?PhotoID=12345) then the information is found in the $_GET array and can be retrieved in the same way as the information in the $_POST array (which you are presumably familiar with if you have dealt with forms).

Is that what I'd want? I know I was taught about GET at the beginning of the semester, but we literally never used it. I'll go read up on it, then. Thanks.

edit; Just looking at w3schools, they still use GET inside of a form. So would I just put the images inside a form and the when the image is clicked, would that count? Sadly, I don't have my laptop with me so I can't try it right now.

Sab669 fucked around with this message at 18:28 on May 24, 2010

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Sab669 posted:

edit; Just looking at w3schools, they still use GET inside of a form. So would I just put the images inside a form and the when the image is clicked, would that count? Sadly, I don't have my laptop with me so I can't try it right now.
You can put a form on a page and specify method="GET", or you can just use a hyperlink and include the desired parameters at the end of the URL. Both will work.

DoctorScurvy
Nov 11, 2005
More of a passing curiosity, really
The general rule of thumb is GET for retrieving data, POST for sending it.

getinfo.php?getthisid=1
php:
<?
$id = $_GET['getthisid'];
?>
<form action='postdata.php' method='POST'>New value: <input type='text' name='setthis'><input type='submit' value='Submit'></form>
php:
<?
$setthis = $_POST['setthis'];
?>

Tivac
Feb 18, 2003

No matter how things may seem to change, never forget who you are

Masked Pumpkin posted:

It probably doesn't even need to be said, but I assume you're validating your inputs, right? $var = htmlentities($var, ENT_QUOTES) works pretty well for me, but if there are better options available, I'd be interested in hearing them.

http://www.php.net/manual/en/book.filter.php

DholmbladRU
May 4, 2006

Lumpy posted:

In addition to this, if you are pulling user info from a DB, you loop through the results in a similar manner:

This would loop through the user data you returned from your query the same way Begby's example looped through an array you constructed manually.

Havnt had a chance to work on this much. Would the fallowing be sufficient to create an object, assign that object values, then store those objects in an array.

php:
<?

$queryResults = mysql_query('SELECT Fname, Lname, PrimEmail, SecEmail, Class, Standing, picture  FROM 'xxx'); 
        $count = 0;
        $arryOfProfile[];
        while( $user = mysql_fetch_object( $queryResults ) )
        {
            $temp = new User();
            $temp->$Fname = $user->FName;
            $temp->$Lname = $user->Lname;
            $temp->$PrimEmail = $user->PrimEmail;
            $temp->$SecEmail = $user->SecEmail;
            $temp->$pClass = $user->Class; //What do I do about this? field is class in database, should I simply rename it?
            $temp->$standing = $user->Standing;
            $temp->$picture = $user->picture;
            
            $arryOfProfile[$count] = $temp;
            $count = $count + 1;
            
            
        }
?>

Begby
Apr 7, 2005

Light saber? Check. Black boots? Check. Codpiece? Check. He's more machine than kid now.

DholmbladRU posted:

Havnt had a chance to work on this much. Would the fallowing be sufficient to create an object, assign that object values, then store those objects in an array.

php:
<?

$queryResults = mysql_query('SELECT Fname, Lname, PrimEmail, SecEmail, Class, Standing, picture  FROM 'xxx'); 
        $count = 0;
        $arryOfProfile[];
        while( $user = mysql_fetch_object( $queryResults ) )
        {
            $temp = new User();
            $temp->$Fname = $user->FName;
            $temp->$Lname = $user->Lname;
            $temp->$PrimEmail = $user->PrimEmail;
            $temp->$SecEmail = $user->SecEmail;
            $temp->$pClass = $user->Class; //What do I do about this? field is class in database, should I simply rename it?
            $temp->$standing = $user->Standing;
            $temp->$picture = $user->picture;
            
            $arryOfProfile[$count] = $temp;
            $count = $count + 1;
            
            
        }
?>

A few tidbits

$temp->$FName

That should be $temp->FName. Using $ in there means to use the value of $FName as the field.

code:
$FName = taco;
$temp->$FName = 'Fred';
// is the same as
$temp->taco = 'Fred';
Instead of $count = $count + 1, you can use $count++ which is shorthand but you get the same result. You could also use $count += 1, whatever floats your boat.

You don't need to use the counter. Instead you can use $arrayOfProfile[] = $temp. The empty brackets means to add a new array value at the end of the array.

code:
$arr = array();
$arr[] = 123;
$arr[] = 456;
$arr[] = 789;

// $arr[0] contains 123, $arr[1] contains 456 etc.
$arryOfProfile[] before your loop, not sure what that is doing, probably just screwing things up. If you are trying to initialize the array, do $arryOfProfile = array();

What is the issue with Class? Are you having some issues with the SQL or something? If that is messing up your SQL statement you can surrount it with backticks `Class` which is the character on the tilda key above tab on your keyboard.


Otherwise I think it should work. Have you given it a try? One thing that will help you as you try this out is print_r, use it to echo out the contents of objects and arrays and such, then view the source code in the browser. That will help you determine if your stuff is working right.

DholmbladRU
May 4, 2006
thanks! Ill take a look at all that and try it out tomorrow when I get a chance. ever done any object oriented php so this is all new to me.
The issue with 'class' is that it is a predefine word used in php. And in my table it is one of the fields.


edit shold have included the class.



php:
<?
class User
        {    
            var $Username
            var $Fname;
            var $Lname='';
            var $PrimEmail;
            var $SecEmail;
            var $Class;
            var $standing;
            var $picture            
        }

?>
I was doing $temp->$Fname = $user->FName; and including the $ on the first value because this is the name of the variable in the class. Is this not correct?

DholmbladRU fucked around with this message at 21:09 on May 25, 2010

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

DholmbladRU posted:

Havnt had a chance to work on this much. Would the fallowing be sufficient to create an object, assign that object values, then store those objects in an array.

php:
<?

$queryResults = mysql_query('SELECT Fname, Lname, PrimEmail, SecEmail, Class, Standing, picture  FROM 'xxx'); 
        $count = 0;
        $arryOfProfile[];
        while( $user = mysql_fetch_object( $queryResults ) )
        {
            $temp = new User();
            $temp->$Fname = $user->FName;
            $temp->$Lname = $user->Lname;
            $temp->$PrimEmail = $user->PrimEmail;
            $temp->$SecEmail = $user->SecEmail;
            $temp->$pClass = $user->Class; //What do I do about this? field is class in database, should I simply rename it?
            $temp->$standing = $user->Standing;
            $temp->$picture = $user->picture;
            
            $arryOfProfile[$count] = $temp;
            $count = $count + 1;
            
            
        }
?>

What Begby said, plus you probably want to initialize your User inside the User class itself:

php:
<?
$queryResults = mysql_query('SELECT Fname, Lname, PrimEmail, SecEmail, Class, Standing, picture  FROM 'xxx'); 
$arrayProfile = array();
while( $user = mysql_fetch_object( $queryResults ) )
{
  $arrayProfile[] = new User( $user );
}
?>

DoctorScurvy
Nov 11, 2005
More of a passing curiosity, really
If I may pull all of the above together

php:
<?
edit - dang, so close but for one line. Continue below.?>

DoctorScurvy fucked around with this message at 08:22 on May 26, 2010

Begby
Apr 7, 2005

Light saber? Check. Black boots? Check. Codpiece? Check. He's more machine than kid now.
Close... but a touch off, should be more like this

php:
<?php
class User {    
    var $Username;
    var $Fname;
    var $Lname='';
    var $PrimEmail;
    var $SecEmail;
    var $Class;
    var $standing;
    var $picture;  

    function __construct($userData)
        {
        $this->Fname $userData->FName;
        $this->Lname $userData->Lname;
        $this->PrimEmail $userData->PrimEmail;
        $this->SecEmail $userData->SecEmail;
        $this->pClass $userData->Class;
        $this->standing $userData->Standing;
        $this->picture $userData->picture;
    }
}
?>


<?php
$queryResults mysql_query('SELECT Fname, Lname, PrimEmail, SecEmail, Class, Standing, picture  FROM 'xxx'); 
$arrayProfile = array();
while($userdat = mysql_fetch_assoc($queryResults)) {
    $arrayProfile[] = new User($userdat);
}
?>

Begby
Apr 7, 2005

Light saber? Check. Black boots? Check. Codpiece? Check. He's more machine than kid now.

DholmbladRU posted:

I was doing $temp->$Fname = $user->FName; and including the $ on the first value because this is the name of the variable in the class. Is this not correct?

Yeah, that is not correct. There should only be a dollar sign on the name of your object, every dollar sign after gets evaluated as another variable as in my example above. If you use $temp->$FName, it will try to use the value of $FName as the field name. If $FName is null, I am not sure what happens, but its definitely not correct.

Are you actually trying any of this code? Do what I said and run print_r and try these things out experimentally and see what happens. Learning by trying, failing, and fixing, will seriously make it so you understand and retain knowledge a lot more than someone telling you how to do it.

rivals
Apr 5, 2004

REBIRTH OF HARDCORE PRIDE!
I'm working on a project on SQL Injections and to show them I'm using a simple PHP login form. I'm noticing some weird behavior that I think is coming from mysql_query() but I'm not positive and I don't really understand it so I'm looking for some help.

Background: I have disabled magic quotes, and this example is from the weakest form with no security so it should be completely vulnerable to injections. The server I'm on has an old version of MySQL which doesn't seem to support '--' for commenting, so I'm using '#'.

Here is the code from my checking function:
code:
$query = "SELECT * FROM plaintext WHERE username='$username' AND
    password='$password'";
$result = mysql_query($query);
return mysql_fetch_array($result);
When I try the injection in the password field, it works. Input:
Username: blah
Password: ' OR 1=1#
code:
query: SELECT * FROM plaintext WHERE username='blah' AND password='' OR 1=1#'
Logged in as root
However when I try the injection in the username field, I get an error. Input:
Username: ' OR 1=1#
Password: s
code:
query: SELECT * FROM plaintext WHERE username='' OR 1=1#' AND password='s'

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in blahblahblah/weaklogin.php on line 18
Invalid username/password combination.
The weird thing is, when I run both of those queries directly on my database, they return the same result. The conclusion this behavior leads me to, is that this specific attack (on this specific page, with this version of MySQL etc) could be solved very simply by just using hashed passwords. I know that's not the best way of course, and my end goal is that the second page would be identical but with hashed passwords, and I was hoping to break it by injecting into the username field like that, and then go on to prepared statements and such.

I've done some (very simple) PHP and MySQL work in the past, nothing ever dealing with logins and sessions though so some of this is new to me. I just don't really understand this behavior at all. Thanks to anyone who can help clear this up.

Peanut and the Gang
Aug 24, 2009

by exmarx
PHP has some weird requirements in order to get a comment to work correctly with mysql_query(). Try using "-- -" as the comment, because it seems to be the magic fix.

rivals
Apr 5, 2004

REBIRTH OF HARDCORE PRIDE!
No such luck, still saying not a valid resource. I never thought I'd have this much trouble breaking something so weak.

McGlockenshire
Dec 16, 2005

GOLLOCKS!
Do a var_dump on $result. Is it false? If so, check mysql_error().

gwar3k1
Jan 10, 2005

Someday soon
Is PDO's bindparam secure enough to do the following?:

php:
<?
  $SQL->bindParam(":uname",$_POST['uname'],PDO::PARAM_STR);
  $SQL->execute();
?>

rivals
Apr 5, 2004

REBIRTH OF HARDCORE PRIDE!

McGlockenshire posted:

Do a var_dump on $result. Is it false? If so, check mysql_error().

Yeah, I checked and $result is false. This is what I get:
code:
query: SELECT * FROM plaintext WHERE username='a' OR 1=1#' AND password='f'
1064: You have an error in your SQL syntax; check the manual that corresponds to 
your MySQL server version for the right syntax to use near 'password='f'' at line 2 
And injecting into the password field still works:
code:
query: SELECT * FROM plaintext WHERE username='asdf' AND password='' OR 1=1#'
0: Logged in as root
EDIT: I just tried putting in random characters after the # in the second example and it still works fine, so I have no clue.

rivals fucked around with this message at 05:55 on Jun 1, 2010

McGlockenshire
Dec 16, 2005

GOLLOCKS!

gwar3k1 posted:

Is PDO's bindparam secure enough to do the following?:
If by "secure enough" you mean "totally the way to do it," then you are correct. You don't strictly need to include the data type unless your database cares about that kind of thing. (MySQL doesn't care, it will magically cast the value. SQLite doesn't care. Postgres might care.)



rivals posted:

Yeah, I checked and $result is false. This is what I get:
code:
query: SELECT * FROM plaintext WHERE username='a' OR 1=1#' AND password='f'
1064: You have an error in your SQL syntax; check the manual that corresponds to 
your MySQL server version for the right syntax to use near 'password='f'' at line 2 
Have you tried putting a space between the # and the 1=1? I'm grasping at straws here, I haven't seen a 3.x version of MySQL in the wild in five years. The 3.x-4.1 documentation suggests you can also try C-style /* */ block comments, though you'd have to combine username/password exploits to pull that off.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

rivals posted:

Yeah, I checked and $result is false. This is what I get:
code:
query: SELECT * FROM plaintext WHERE username='a' OR 1=1#' AND password='f'
1064: You have an error in your SQL syntax; check the manual that corresponds to 
your MySQL server version for the right syntax to use near 'password='f'' at line 2 

I'm not totally clear on why you're mucking about with comments, which as you can see are not particularly portable and often have weird syntax glitches because they are parsed differently than other components. If you set the username to something like ' OR ''='' OR ''=' then you'll wind up the statement SELECT * FROM plaintext WHERE username='' OR ''='' OR ''='' AND password='f' which because AND has higher precedence than OR and both are left-associative is parsed as SELECT * FROM plaintext WHERE (username='' OR ''='') OR (''='' AND password='f') which selects all rows.

If you want just a particular username, you could use user' OR 'x'=' and get SELECT * FROM plaintext WHERE username='user' OR 'x'='' AND password='f' which parses like SELECT * FROM plaintext WHERE username='user' OR ('x'='' AND password='f') which can be seen to just select the row for that username.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
Here's a question that will probably be ignored, as it's a bit odd:

Suppose I want to get additional functionality that essentially requires a new control structure or language construct in the code I write, what options do I have?

My motivation for thinking about this is as follows: I would like to be able to have my scripts output nicely indented HTML, but for ease of editing I also want to have the HTML appear verbatim in my PHP code with indenting that respects the eventual indenting of the HTML and at the same time the indentation level of the surrounding PHP.

So the following (for a crude example) results in nice HTML, but doesn't look nice in my PHP:

code:
<doctype blah blah whatever>

<html>
    <head>
        <title>My page</title>
    </head>
    <body>
        <h1>My page</h1>
        <table>
            <thead>
                <tr>
                    <th>Butt</th>
                    <th>Wiener</th>
                    <th>Saucepot</th>
                </tr>
            </thead>
<?php

    // some code

    for ($i=0;$i<$something;$i++) {
        echo "            <tbody>
                <tr>
                    <td>$pizza</td>
                    <td>$cabbage</td>
                    <td>$dickbutt</td>
                </tr>
";
        for ($j=0;$j<$somethingelse;$j++) {
            if ( I have had my dinner ) {
                echo "                <tr>
                    <td>{$badger[$j]}</td>
                    <td>{$cherub[$j]}</td>
                    <td>{$cobweb[$j]}</td>
                </tr>
";
            }
        }
        echo '            </tbody>
';
    }

?>        </table>
    </body>
</html>
What I would really like is to be able to type something like this (inventing syntax with gay abandon):

code:
<?php

    // some code

    for ($i=0;$i<$something;$i++) {
        emit [common initial whitespace --> 12 spaces] {
            <tbody>
                <tr>
                    <td>{$pizza}</td>
                    <td>{$cabbage}</td>'
                    <td>{$dickbutt}</td>'
                </tr>
        };
        for ($j=0;$j<$somethingelse;$j++) {
            if ( I have had my dinner ) {
                emit [common initial whitespace --> 16 spaces] {
                    <tr>
                        <td>{$badger[$j]}</td>
                        <td>{$cherub[$j]}</td>'
                        <td>{$cobweb[$j]}</td>'
                    </tr>
                };
            }
        }
        emit [common initial whitespace --> 12 spaces] {
            </tbody>
        }
    }

?>
um, and I guess some extra syntax to control line breaking before and after a {} block after an "emit".

Begby
Apr 7, 2005

Light saber? Check. Black boots? Check. Codpiece? Check. He's more machine than kid now.

Hammerite posted:

Here's a question that will probably be ignored, as it's a bit odd:

One thing that might solve your problem is to use some sort of templating system. Smarty actually has syntax very similar to what you have in your example. You will need to keep most of your PHP logic in separate files, but thats actually a really good thing.

I am not saying to necessarily use Smarty, there are other templating systems out there. Check them out and see if it will solve your problem.

McGlockenshire
Dec 16, 2005

GOLLOCKS!
Have you tried the tidy extension? Though it seems to kill whitespace, not structure it. Hmm. Alternatively, you could load your output into a DOMDocument using loadHTML() and then manually perform output by crawling the DOM.

Neither of these is likely to be very fast.

McGlockenshire fucked around with this message at 05:41 on Jun 2, 2010

Adbot
ADBOT LOVES YOU

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
Interesting idea, yes, some kind of templating system might be a step forward. Thanks for the suggestion!

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply