Re: [PHP] Is there a way to use the strpos() for next string...

2003-11-20 Thread Kelly Hallman
On Thu, 20 Nov 2003, Scott Fletcher wrote:
> How exactly does the 3rd parameter option work.  I tried this but it
> doesn't work, so I don't know how exactly does it work...  There isn't
> detail information on the php.net website...

"The optional offset parameter allows you to specify which character in 
haystack to start searching. The position returned is still relative to 
the the beginning of haystack."

So if you are trying to find subsequent occurrences of the string, you'd
need to make the offset be greater than the last character you checked, or
you're going to keep getting the first occurrence.

>$XML_Start = (strpos($res_str,"",1);
>$XML_End = strpos($res_str,"]]>",2);

If you're just trying to pull one bit of data out of a file, you might
want to look into regex for this purpose. If you're actually trying to
write a parser, I think you might do well to read up on how other parsers
work (like, using a stack). Anyway, don't do that, use an existing XML
parser.. unless you are on a learning quest.. then, by all means!

-- 
Kelly Hallman
//Ultrafancy/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] array_search

2003-11-20 Thread Kelly Hallman
On Thu, 20 Nov 2003, Jay Blanchard wrote:
> $foo = $_POST['textarea'];
> $newFoo = str_replace("\n", " ", $foo);
> $arrayFoo = explode(" ", $newFoo);

In the code above any spaces on the lines will also be delimiters...
I missed that part of the requirement...?

Maybe I'm not understanding the problem, but why not just use something 
like $myarray = preg_split('/[\r\n]+/', $textarea) ?

-- 
Kelly Hallman
//Ultrafancy/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Is there a way to use the strpos() for next string...

2003-11-20 Thread Kelly Hallman
On Thu, 20 Nov 2003, Scott Fletcher wrote:
> > Anyway, don't do that, use an existing XML parser..
>
> I'll try.  I haven't got the PHP XML Parser to work, I think it is
> because the XML stuffs I receive is not a true XML, some of them don't
> have a closing tag either because one tag have actual data as an
> attribute inside one tag.  It is kind of frustrating to on not knowing
> what XML Parser will work.

I was only suggesting that rather than try to perfect your own parser,
you'd be better off spending that time getting comfortable with something
that already exists for this purpose. There is too much debugging,
testing, optimization and research required to build one that is adequate,
and many already exist that probably exceed any home-brew solution.

I have not done too much XML parsing in PHP yet, but you might look to 
PEAR for help with this. I've briefly experimented with the various PEAR 
XML packages, like XML_Tree and XML_Parser. Take a look:
http://pear.php.net/packages.php?catpid=22&catname=XML

If you're dealing with poorly formed XML then you've got another problem
if you're trying to actually parse it. To simply pull one or two values
out of the file, a regex still might be the quickest/dirtiest..

If you do want to move forward testing parsers and stuff, make yourself a
valid XML file to test with, so that is not the issue...worry about fixing
malformed XML later with the provider or through an intermediate filter..

-- 
Kelly Hallman
//Ultrafancy/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Adding X days to a time string...

2003-11-21 Thread Kelly Hallman
On Fri, 21 Nov 2003, Jeff Lewis wrote:
> Sorry, I may have muddled that...the issue isn't converting a string to
> a time, it's taking a time (102636 for example) and adding 30 days

Having it in seconds since the epoch makes this pretty easy
(60 * 60) * 24 = 86400 // seconds in a day
(86400 * days) + timestamp

-- 
Kelly Hallman
//Ultrafancy/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] strpos() act funny when searching for "]]>"....

2003-11-21 Thread Kelly Hallman
On Fri, 21 Nov 2003, Scott Fletcher wrote:
> Ah!  Found the problem... It is probably a bug with strpos() because it
> seem to get stuck in there and couldn't get out of it somehow.  The
> workaround the problem I did was just easily increment the $HTML_End by 1
> and that fixed the problem.  It look like this...

You should avoid statements like "_ doesn't work" (try "I can't get it
to work" or "it doesn't work for me") and "It's probably a bug with"...

Anyway, strpos() is working exactly like it's supposed to...
Consider this code:

$t = "** string string string";
$l = strpos($t,"string"); // $l == 3

Now, if you tell strpos() to start searching at offset 3 for the same
exact string, it's going to find the same occurence because you're telling
it to start looking exactly where it found it last time.

So, naturally, you need to advance the character position by at least one
to find subsequent occurences. This isn't a workaround. You had the bug.

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] echo or print

2003-11-21 Thread Kelly Hallman
On Fri, 21 Nov 2003, Wouter van Vliet wrote:
> Point is, which of the inline printing style is preferred by you guyes. I
> tend to use  a lot, since it reads easier but get into struggles
> with myself when I do that multiple times in a row.

Ultimately I think you'd want to be doing very little of any, if you're 
working with more than a basic, one-page script.

Even if you are (gulp) generating your HTML output within functions, it
seems better to be returning that back to some level where there are only
a couple of echo/prints necessary..

Think output layer...

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: A loop for the hours in a working day

2003-11-23 Thread Kelly Hallman
On Sun, 23 Nov 2003, Shaun wrote:
> Sorry, worked it out, here it is if anyone needs it :)
> $minutes = array("00", "15", "30", "45");
> $hours = array("07", "08", "09", "10", "11", "12", "13", "14", "15", "16",
> "17", "18", "19");
> for ($x = 0; $x < 13; $x++ ) {
>for ($y = 0; $y < 4; $y++ ) {
> echo "".$hours[$x].'.'.$minutes[$y].""; } }

That works, but it's a little unweildy.. especially if you want to change 
the range later (changing the array may not be so bad, but then you've 
got to figure out how many iterations your loops must do, etc).

How about something like this:

$hstart = 7; $hend = 19; $interval = 15;

for($h=$hstart; $h < $hend; $h++) {
  for($m=0; $m < 60; $m += $interval) {
echo sprintf("%d:%02d",$h,$m); } }

Used sprintf in order to make 0 minutes display as 00. This would be a 
great candidate for something to make into a function...

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] ldap_search() question

2003-11-23 Thread Kelly Hallman
On Sat, 22 Nov 2003, Schechter, Ricky wrote:
> Do I use ldap_search to authenticate users in LDAP?  I can successfully
> search the LDAP and retrieve user's data based on a search criteria like
> (cn=something). If I use (password=somepass) or (userPassword=somepass)
> in the search criteria it comes back with no hits. How should this be
> done? Do I have to encrypt the password somehow?

You probably need to use ldap_compare() to verify the password. Most LDAP 
servers won't send back the password field contents. Hope that helps!

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: A loop for the hours in a working day

2003-11-23 Thread Kelly Hallman
On Sun, 23 Nov 2003, David Otton wrote:
> >How about something like this:
> >$hstart = 7; $hend = 19; $interval = 15;
> >for($h=$hstart; $h < $hend; $h++) {
> >  for($m=0; $m < 60; $m += $interval) {
> >echo sprintf("%d:%02d",$h,$m); } }
>
> Couple of suggestions on top:
> replace "echo sprintf" with a simple "printf".

Yes.. I thought it would be more illustrative to use sprintf, as printf
alone might look more foreign and is less versatile in this case
(especially were it made into a function)...

> If I was going to bother to use a function here, I'd work with unix
> timestamps and strftime() (http://www.php.net/strftime) so my function
> would return values in pretty much any format, and at 1 second res...

Well, sure.. but that would be overkill for a simple select list
of the type described.  As for coding it as a function, I was only trying
to suggest this is the type of thing that makes a good function--not that
what I put down there would make the ultimate function of this type.

I thought taking it further and making it into a function myself
1) might seem like I was trying to be showy and 2) feared the example 
would start losing it's demonstrative value with extra functionality.

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] PHP Java extension--hopeless?

2003-11-26 Thread Kelly Hallman
I am trying to find help or information on running the Java extension with
PHP under Apache on Redhat Linux using a Sun JVM.

I am aware that the PHP documentation says that the Java extension is
experimental. I am also aware that people say the ISAPI version does not
work well and that running PHP as a CGI should give better results. We've
tried, and so far it doesn't seem to be more reliable.

Oddly, it does work most of the time. However, maybe 3/10 times or so it
gives an error. When using the Java extension with PHP running as ISAPI,
PHP gives the error "Unable to create Java Virtual Machine" .. when
running as a CGI I get that or one of several different errors--again,
only part of the time. That is, when an error does appear, refreshing the 
page once or twice will usually bring up the correct output.

A bit more background: The company I work for has a single sign-in system
for web access. You check for a cookie and redirect to another site if the
cookie is not set.  That site authenticates the user via a web-based
login, sets the cookie, and redirects back to your site. Your site then
reads the cookie and decrypts it using a Java object.

At first, I was frustrated that the cookie decrypter was only available in
Java.. However, after a while I began to see why they chose to do it this
way: so that you could decrypt the cookie from various languages and
platforms, but they only needed to maintain one code base.

Now, I'm just frustrated that PHP doesn't work very well with Java.  
Myself and several others have looked extensively for the answer to this 
and we've tried all the viable remedies that have been suggested.  Does 
anyone have any suggestions?  Also, can it be confirmed or denied that 
Java support will eventually be dropped from PHP?  Plans to improve it?

Thanks in advance for any help or pointers!!

--
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP Java extension--hopeless?

2003-11-26 Thread Kelly Hallman
On Wed, 26 Nov 2003, Rasmus Lerdorf wrote:
> On Wed, 26 Nov 2003, Kelly Hallman wrote:
> > I am aware that the PHP documentation says that the Java extension is
> > experimental. I am also aware that people say the ISAPI version does not
> > work well and that running PHP as a CGI should give better results. We've
> > tried, and so far it doesn't seem to be more reliable.
> 
> Not sure how ISAPI has anything to do with Apache on Redhat here.  But I 
> guess you are just making two disjointed comments.

Yes, the statements were not connected, I just wanted to pre-empt a bunch 
of responses stating things I'd already read or already tried.

> > Oddly, it does work most of the time. However, maybe 3/10 times or so it
> > gives an error. When using the Java extension with PHP running as ISAPI,
> > PHP gives the error "Unable to create Java Virtual Machine" .. when
> > running as a CGI I get that or one of several different errors--again,
> > only part of the time. That is, when an error does appear, refreshing the 
> > page once or twice will usually bring up the correct output.
> 
> Ok, maybe not.  So which is it?  There is no ISAPI for Linux.

ISAPI is probably not what I meant; I meant apache module version vs. CGI
version. I have tried them both, and both give similar results. Sorry, I
was talking to someone today who was referring to the apache module
version as ISAPI.. I really have no idea what ISAPI exactly is (based on
what you've said I'm guessing it's an IIS API), or if 'apache module
version' is the correct terminology either... Sorry! :)

> Having to run a Java emulator just to decode a cookie sounds absolutely
> nuts to me.  Can you not get the algorithm for decrypting this cookie
> and write it in C?  That's how everyone else achieves portability.

Right, I agree this is a very bassakwards way of going about it.. In this
instance, performance is not really an issue as much as politics.. but
this comment is useful as we may be able to persuade them into providing
information about the algorithm in use, to develop something more usable.  
We are the small fish, and the big fish provides this service.. it's
politically beneficial to us if we could get it running in the short term,
but it appears that the Java extension really isn't ready for prime time..

Fortunately I've made contact with the guy who developed the Java code, 
and he has a vested interest in getting it to work with PHP too, so maybe 
in the longer term we can find a better solution...

> The demand has been very low and volunteers to improve it are hard to 
> find.  If someone steps up to do it, it will improve.

That is what I expected to hear. I didn't expect any magic bullet answer,
I am just looking for comments like the ones you gave--so I have some
substantiation if the answer ends up being we can't get it to go.

Thanks!!

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular expressions

2003-11-27 Thread Kelly Hallman
On Thu, 27 Nov 2003, Eugene Lee wrote:
> Instead of using regexps on the URL, it might be easier (and safer) to
> loop through $_GET, build a new $geturl array, add/delete/change any
> variables in $geturl, then build a new $geturlstr string that can then
> be appended to your hyperlinks.

What about something like this:

$newvars = array("page2" => 3);
$urlstring = http_build_query(array_merge($_GET,$newvars));

It looks like http_build_query() is a pretty new feature so you could make 
a basic replacement for it like so:

if (!function_exists("http_build_query")) {
  function http_build_query($data) {
if (!is_array($data)) { return; }
foreach($data as $k => $v) { $r[] = "{$k}=".urlencode($v); }
return implode("&",$r); } }

Also, a way to filter the keys from the $_GET url may be useful here:

function key_filter($data,$allowed) {
  foreach($data as $k => $v) {
if (in_array($k,$allowed)) { $r[$k] = $v; } } return $r; }

Putting it all together:

$allow_keys = array("action", "page", "custtype", "gender");
$new_vars = array("page" => 3, "action" => "newaction");

$urlstring = http_build_query(
  array_merge( key_filter($_GET,$allow_keys),$new_vars) );

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] php as cgi script

2003-11-28 Thread Kelly Hallman
On Fri, 28 Nov 2003, Nicole Lallande wrote:
> Ivone --
> You are using a PERL invocation for php.  PHP scripts begin  the # sign is a comment in PERL - not in PHP.

# also denotes a comment in PHP. Though #! is not a comment, per se.  
(However, if you feed the file directly to some interpreter like perl, it
does have the benefit of being ignored as a comment.)

> To run php as cgi you need to install the php cgi version (as opposed to
> the apache modular installation.)  That will allow you to run cgi
> scripts on the command line.

CGI stands for common gateway interface, which is the interface between a
web server/request and some external program, so it has little to do with
the command line. However, to run PHP from the command line, you do need
to run it with the "CGI version" of PHP. The question did not specify 
needing to run PHP from the command line, but as a CGI by the webserver.

--
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variable in $_FILES?

2003-12-01 Thread Kelly Hallman
On Mon, 1 Dec 2003, Dimitri Marshall wrote:
> This is what I'm trying to do:
> $pic = $_FILES['object$objectNumber'];
> $picName = $pic['name'];
> ...
> $objectNumber is being defined, but for some reason this code won't work.
> Can someone tell me why and also what I can do to make it work?

$_FILES["object$objectnumber"] will do it...
( or $_FILES['object'.$objectnumber] )

When you enclose a string in double quotes ("") PHP will interpolate 
variables within the string, as you are trying to do.

When you enclose a string with '' it will be treated as a literal.

You may also consider "object{$objectnumber}" if you need to avoid 
ambiguities with the rest of your string. I personally think it's a good 
habit to use the curlies anyway, but I'm sure that's a matter of debate..

--
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Problems downloading files via https in IE 6

2003-12-06 Thread Kelly Hallman
On Sat, 6 Dec 2003, Geoffrey Thompson wrote:
>   header("Content-Type:application/csv");
>   header("Content-Disposition:attachment; filename=downloadFile.csv");
>   header("Content-Transfer-Encoding:binary");
>   fpassthru($fp);
> 
> This works great in Mozilla and IE 6 via http, and it works in Mozilla
> via https, but for some reason in IE 6 via https, my filename is
> mysteriously replaced by a truncated version of my page url.  This
> results in an error, because the file (obviously) cannot be found to be
> downloaded. Is it something I'm doing, or is this an IE problem?

This is the workaround I use for the IE/https download problems.
Not sure if it's the same problem, but let me know if this helps:



-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] restrict access to multiple pages

2003-12-09 Thread Kelly Hallman
On Mon, 8 Dec 2003, Chris W. Parker wrote:
> Ok so I am working on the admin sectin of the e-commerce app I'm writing
> and I'm hoping there's a better way to do what I am currently doing.
> In an effort to prevent circumvention of the login page I've placed a
> check at the beginning of each page that basically does the following:
...

In the case that this is part of a larger application, as it seems to be, 
you probably should have an include that you are doing on each hit that 
handles the user identity/authentication.. Not just for your admin users, 
but a general container for all the user-related functions.

On that page Within that include, let's call it loguser.php, you could
write functions such as require_admin() or require_login() .. then, call
those functions on the pages that require the user to be an admin or be
logged in. The functions would determine if the logged-in user had
adequate permission, and redirect them if not. That way, you can control
this behavior from a central location--you don't want to have to go
through each page of your app and change a URL.

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] header function, I'm stumped

2003-12-09 Thread Kelly Hallman
On Tue, 2 Dec 2003, Chris Hubbard wrote:
> All, dealing with header("location:...") again.  and trying to
> understand what's happening. I've got the following code:
> header("Location:http://www.mysite.com/cp/ad/ad_details.php?id=";. $id);

I'm kinda surprised I didn't see this mentioned.. Have you tried:
header("Location: http://url.redirect/\n\n";); exit; // ?

The browser may be particular about the headers. When you add the two 
newlines to the end, it makes it look like the end of the headers.

It's good practice to explicitly exit each time you redirect.

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular Expression

2003-12-27 Thread Kelly Hallman
On Sat, 27 Dec 2003, Joshua wrote:
> I'm trying to change the string, for example,
>
> $string = "11.abcd.32.efgh.53.ijk";
> to
> 
> 11.abcd.
> 32.efgh.
> 53.ijk.
> 
> with ereg_replace. Like 
> ereg_replace("\.[0-9]","",$string);
> How can I recover the original characters after replacing them with 
> in ereg_replace?
> 
> ereg_replace("\.[0-9]","\\0",$string) gives me the
> wrong result like:
> 
> 11.abcd.
> 32.efgh.
> 53.ijk.

Since the output you want and the output you didn't want are identical in
your post, it was hard to tell what you were trying to do, but...

I think this is what you want..
ereg_replace("(\.)([0-9])","\\1\\2",$string);
(minus the last decimal point, missing from your original string)

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] if("NANC" < 0) - always evaluates TRUE...

2004-01-06 Thread Kelly Hallman
On Tue, 6 Jan 2004, Ivo Pletikosic wrote:
> $data = 'NANC';
> if(is_numeric($data) && $data < 0) { die('Not OK'); }

Interesting problem, one of the first legit oddities I've seen since
joining the list.  Anyway, in addition to your workaround, casting the
variable as an int also appears to result in the desired behavior:

(int)"NANC" < 0 == false

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Verifying a url

2004-01-06 Thread Kelly Hallman
On Tue, 6 Jan 2004, Ivo Pletikosic wrote:
> It did not work for me but since I have only one http port and one https
> port on my server i use instead
> 
> if( $_SERVER['SERVER_PORT'] == "80" ) echo 'http';

Here's a way you could write it in your script...
$is_secure = ($_SERVER['SERVER_PORT']==443) ? true : false ;

If you decide to use SERVER_PORT to sense secure connections, this logic 
would work well. It only depends on knowing the port you consider secure.
For typical https, that would be port 443. Enjoy!

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Problem with Picture Name

2004-01-06 Thread Kelly Hallman
On Tue, 6 Jan 2004, Dimitri Marshall wrote:
> I had it perfect so that when someone uploaded a picture in a form, it
> uploaded to my server and saved the image name in the database. The
> problem is, what if someone tries saving a picture with an apostraphe ie
> ( ' ) or ( " )? Can someone help me out?"

I'd recommend sanitizing the filename using a function something like:

function clean_filename($fname,$repl="",$regex="/[^-A-Za-z0-9_\.]+/") {
return preg_replace($regex,$repl,$fname); }

$fname  = "This is a 'filename'.txt";
$fname1 = clean_filename($fname); // Thisisafilename.txt
$fname2 = clean_filename($fname,"_"); // This_is_a_filename_.txt

I realize this is a very basic function, but it provides a good starting
point. If you want to change the behavior later, you only have to do it in
a single place. Also, it includes defaults that don't need to be specified
with each call, as you'd need to do with preg_replace() alone.

--
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] not sure why regex is doing this

2004-01-09 Thread Kelly Hallman
On Fri, 9 Jan 2004, craig wrote:
> (4536,'golf tournament management',430,0,0),
> (1434,'Premium golf balls',,,0),
> 
> I have to replace the blank entries (,,) with NULLs, using this regex:
> $query = preg_replace('/,\s*,/',',NULL,', $query, -1);
> after this line, only ONE of the ,, sets is replaced by ,NULL, like:
> (1434,'Premium golf balls',NULL,,0)

The regex does continue trying to make matches, but the point at which it
continues is just past your replacement. In other words, the trailing
comma in ,NULL, is not considered part of the string to match/replace.

This should do the trick:
preg_replace('/,\s*(?=[,\)])/', ',NULL', $input);

(?=pattern) is a positive lookahead. It evaluates true if the next 
characters match the pattern, but those characters are not consumed.

So that regex is equivalent to "match a pattern starting with a comma 
followed by any existing spaces, ONLY IF the next character is , or )"

The most robust way you could write this regex is:
preg_replace('/([,\(])\s*(?=[,\)])/', '\1NULL', $input);

I know you'll probably never have input like (),
but it would work as expected.

Many tricky regex problems can be solved by lookaheads. There is also a
negative lookahead (?!pattern) ... also note that this is an advanced
regex feature and won't it work on many regex engines not based on PCRE.

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] php doesn't work in html files

2004-01-11 Thread Kelly Hallman
On Sun, 11 Jan 2004, MadHD wrote:
> Try to rename the .html file in .php (index.html -> index.php) and test
> it. You can reconfigure apache to pass all .html files to php compiler
> but i don't recommend it because it reduce drastically the performance.

...IF those .html files don't mostly all contain PHP code.
Same performance hit if you were naming plain HTML files as .php...

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Re: jpeg Uploader issue

2004-01-12 Thread Kelly Hallman
On Mon, 12 Jan 2004, Mike R wrote:
> > i had a problem like the one you descriped. The problem was quite
> > simple. In my case everything worked fine with Windows-Web-Browsers
> > but not with MAC-Browsers. Check the value of the filetype variable.
> > There might be differences between different plattforms.
> 
> I'm sorry to sound stupid here, but what do you mean by that? :\

This occurred to me too, but I couldn't find the thread to respond...

I think he means that the server may be returning an incorrect
Content-type header for jpeg images. IE is especially notorious for
(incorrectly) ignoring this information if it can match the file extension
to a file type registered on the local machine.

In an ideal world, all http clients should respect the Content-type header
to determine the file type. A .jpg should be Content-type: image/jpeg

Normally this is set in your server configuration. However, if they are
being served by a script that is outputting the raw data to the client,
you may need to send this header from the script.  That would explain why
Mac users see the problem only with uploaded images (did you say?).

In PHP you would set the Content-type header like so:
header("Content-type: image/jpeg");

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] _("What does this do?")

2004-01-12 Thread Kelly Hallman
I just ran across this syntax in someone else's code.
I can't detect any difference between these two expressions:

_("String value") and "String value"

Is there a difference? What does _("xyz") do, and is it documented
anywhere? I'm curious why this code (SquirrelMail) uses it in one place,
but not another. What say you, PHP gurus? Gotta love the syntactic sugar!

--
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] class design question

2004-01-12 Thread Kelly Hallman
On Mon, 12 Jan 2004, rogue wrote:
> i am working out the finishing touches on a authentication class that
> uses mysql to store the time of last access and some other goodies.
> 
> my question is, when developing a class that uses a database, what is
> the best way to handle the database bit? for now i just set the
> connection in an .inc file and include that in the class, but there has
> got to be a better way - especially for portability sake.

As previously suggested by another poster, check out PEAR's DB class. I
wrote my own database class and used it in almost everything I wrote for a
long time, but eventually for "portability" sake, I moved to PEAR::DB.

Just instantiate the database connection object and attach a reference to
your authentication object. Then access the database object's methods as
you normally would from the object reference attached to your auth object.

Structure things right and it's very easy to do. It avoids the pitfalls of
some of the other approaches, like accessing some sort of global.

The DB class also allows you some manner of database abstraction for a 
modicum of portability if you should need it (it's the SQL queries 
themselves that are not always portable, so you have to solve that).

If you've never looked at PEAR, the DB class is a good start.
Also, despite all it's features, it's quite fast!

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Adding a realtime monitoring console

2004-09-01 Thread Kelly Hallman
I'm developing a web-based framework ("the application") and would like to
implement an ncurses-based realtime monitoring facility ("the console"). 

The application currently writes events to a database history table, but I
don't think having a console that constantly requeries that table would be
efficient for monitoring realtime activity. So that's out.

The most appealing method (in my mind) is to develop a socket protocol
that allows the application to communicate with the console. The drawback
here seems to be that the console will not usually be active, and I'm
concerned that attempting to establish a connection will impose too much
overhead since most often there will be nothing listening.

The most viable solution I can dream up is writing events to a log file,
and have the console (basically) "tail -f" that file to watch the online
activity. The added value of this approach is a log file can be archived
easily or analyzed offline without the need for a database. Potential
drawbacks include the overhead of file I/O and file locking, etc.

Interested to hear anyone's thoughts on either of these ideas (pros/cons) 
and/or any other ideas I've not considered (syslog? others?)...

Has anyone done this before? Is there anything already available?
If anyone else is interested, I would be willing to share the eventual 
technique and code with interested parties.

TIA! --Kelly

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Serializing objects and storing them is sessions [fixed]

2004-04-09 Thread Kelly Hallman
Apr 9 at 2:49pm, Jason Giangrande wrote:
> Kelly Hallman wrote:
> > Try it without serializing, it works.
> 
> After retesting, it seems you are correct.  I guess the same bad 
> __sleep() code that was causing the object not to unserialize at all was 
> also preventing automatic serialization.

For some reason, if I include a __sleep() method in an object, PHP
segfaults on me...so I couldn't tell you anything about that :) Argh!

> However; it does not seem to harm anything if serialize() and
> unserialize() are called manually on an object.  It's just extra code
> that doesn't do anything, and therefore, can be removed.

In my testing, I tried to create an array with a value that was an object. 
I serialized that, and the object was not serialized and that key did not 
appear in the returned serialized representation of that array.

I don't know the default session handler's internals, but if you look at a
session file that it creates, it seems to serialize the $_SESSION array. 
If any of the values are objects, they appear to be serialized as well.

Given the above facts, my guess is that the handler actually goes through
and serializes any session variables that are objects (or perhaps any
values !is_scalar()), then serializes the entire $_SESSION array.

If that is the case, my original claim that a session variable that was
serialized would then be serialized again is probably untrue. The reason
being that the serialized session variable would be a scalar value and the
asession handler would not serialize it again.

So you're correct, it's the same difference. The only downside I can see 
to serializing it yourself is that you've got to always unserialize it 
before you can do anything with it. Then, you'd also need to reserialize 
it and store the result back into that session variable.

If you just let the session handler do the serialization then you can use 
that object directly and any changes would not require reassignment.

$User =& $_SESSION['User'];
$User->loggedin = true;

versus

$User = unserialize($_SESSION['User']);
$User->loggedin = true;
$_SESSION['User'] = serialize($User);

Of course, the first example could also be written as:
$_SESSION['User']->loggedin = true;

I always assumed that serialize would just serialize objects that were
within an array, and that the session handler was merely doing something
like serialize($_SESSION); So I learned something about serialize() and
the session handler's behavior in regards to how it deals with objects. 

-- 
Kelly Hallman

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Serializing objects and storing them is sessions [fixed]

2004-04-09 Thread Kelly Hallman
Apr 10 at 1:39pm, Tom Rogers wrote:
> Is your __sleep() function returning the array required by serialization?

Since you mentioned it, I tried returning an array and it did not
segfault, thought it was initially unclear what the array was for.

After reading over most of the documentation about serializing objects for
the Nth time, I finally found this sentence, which I didn't recall:

"It can clean up the object and is supposed to return an array with the 
names of all variables of that object that should be serialized."

I guess that's pretty clear, but it's not the first time I missed a
half-sentence in the manual that provided a very key bit of information.  
It doesn't help that this is the only mention within serveral full pages
related to the topic of serializing objects.

I think "must" seems more apropos than "supposed to" considering the
result/consequence... It's probably just my older version of PHP, but a
segfault seems like a pretty extreme error message :)

Thanks for pointing me in the right direction! It's so much easier to find
the explanation when you already have the answer

--Kelly

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] class design

2004-04-13 Thread Kelly Hallman
Apr 13 at 2:24am, Andy B wrote:
> instead of making one super huge class..
> turn that class into a bunch of mini classes.
> DbConnect, DbError, DbQuery, DbResult and so on...

Right; chances are if you had all the functionality in one class, it's 
going to be pretty identical to writing it without using a class.

Above you've listed several logical classes you might use with databases.  
They make perfect sense because they represent tangible "objects" as you
might think of the process in an abstract sense. I think breaking down the
parts of the real-world process is a great start to approach OO design.

> i can see writing different classes for different sections of db use but
> unless my mind is super limmited right now that isnt really 100%
> possible or reasonable considering that some of those classes might only
> have 1 or 2 different functions in it... but then again i guess super
> small exact easy to figure out classes are the best??

First, there is nothing unreasonable or impossible about a class with one
or two methods. If it's a logical delineation, that seems perfectly fine.
In most cases, you might rough it out like that in your mind, but as you
are writing the code (or next week), new methods will occur to you.

Since you have created an object that makes sense, you've got an inherent
place to put that newly conceived code. Better to realize your DBQuery
object could use a method to write a SELECT query than to realize your
DBConnection object has a bunch of methods that actually should become a
DBQuery object that you didn't create because it seemed too lean.

To be more specific, breaking these methods into logically grouped classes
enables you to structure your code in a way that leverages OO. Rather than
manually handling a query result value, you can encapsulate a query result
into an object and have your DBQuery object return DBResult objects.

Imagine a function that returns an array. To make use of that array
result, the coder you must know what the array result means and write code
that incorporates that logic, every time it's used. Your code needs to,
for example, pull out a certain key to find a value within the result
data. If that key changes, then so too must all that code.

Compare this with returning an object--now your code does not need to work
with the structural nature of the result, it must only operate the
object's interface to fetch the value. This 'encapsulation' allows you to
freely alter the inner workings of an object without having to alter any
of the code that uses the object (provided you don't break the interface).

Illustratively, compare these arbitrary (and utterly generic) examples:
$x = $result['fields']['display']; // OR
$x = $result->getField('display');

The skeptic may not see a difference, however, suppose your results become 
more complex and now you'd like to change the structure of your result...
$x = $result['mydata']['fields']['display'];

Handling the array yourself now becomes much more overhead, because you've
got to go change all the occurrences. Whereas, encapsulated in an object,
the code would not need to change assuming you preserved the interface.

In many ways, returning an array is not much different from returning an
object, except the object has functionalities (methods) that operate on
the data, rather than relying on your knowledge of the data returned.  
Now the coder needs only use the object's interface. So you see, an
object is merely a complex data structure that 'does stuff'.

The point being, objects can interact in a way that more closely
represents the actual concept rather than arbitrary code required to
interpret the data in a way that relies on the coder's knowledge of the
structural content. Furthermore, the object's data structure can now be
changed centrally, with no ill effects on the rest of your code.

As for a strategy to approach the design, just begin thinking of the
problem in the abstract. How do you represent the process in more human
terms? What would the data do, if it had a brain? Model your objects
against that paradigm, and the code will begin to write itself. Okay,
maybe not quite, but it's much easier than it seems because the code flows
from real-world logic processes rather than being dictated by programmatic
issues you may need to address without OO.

Try it out, think conceptually. Get crazy: the more creative you get with
these ideas, the more neat things you'll find to do with OO. Often this
design process may require multiple revisions until you hit the right
balance. Like any design effort, it's worth the time--and gets easier.

--Kelly

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP Web-Chat Software

2004-04-13 Thread Kelly Hallman
Apr 13 at 4:04pm, Terence wrote:
>  while (10==10) { // cool while loop
> /* ... */ flush(); sleep(1); } ?>

Not sure I see the efficacy of this approach for the problem at hand, but 
what gets me is the cool while loop :) 10==10 is always going to evaluate 
true, and I realize that this is an infinite loop (until script times out) 
but why not just while(true) { } or, more commonly, while(1) { } ...?
That's a rhetorical question, by the way :)

--Kelly

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: smarty

2004-04-14 Thread Kelly Hallman
nd I'm
not convinced that many of these people truly grasp Smarty (even if they
have used it, or claim to like it for some purposes).

Unfortunately the end result is either you see it, or you don't. I would 
really love to post some magical, succinct example that would prove my 
point. If I could do that, I'd move right on to elucidating the ultimate 
OO example to put that issue to rest too.

The point is, if you only work with designs that simple, don't bother. 
These approaches were not designed to solve those problems. So the fact 
that those problems can be easily solved with an alternative method 
really does not move the discussion forward a bit.

I'm all for a discussion about these issues, were the topic "How can I do
it without Smarty?" but to chime in everytime someone tries to advocate a
valid, useful tool.. Aside from being slightly off-topic, and raising the
dander of people who are harnessing the power of those tools, my main
concern is that this may deter some less-experienced coders away from
something that could potentially take their work to new levels.

Regardless of the merit of the point being made, I don't think that
benefits anyone much. I'm sure when some guy came up with a metal knife,
there was a dude there with a sharp rock saying, "but this works too!"  
Then the guy with the knife started using it to cut everything, while the
rock required constant honing to remain sharp enough to do half the work.  
But the guy with the rock thought it was all he needed! I use a knife.

-- 
Kelly Hallman

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Help with shorting this please

2004-04-19 Thread Kelly Hallman
Apr 19 at 10:03am, Don Myers wrote:
> PHP gurus. I know this can be made shorter but I can't seem to figure
> out how. This is a PHP CLI script I use to go through a directory
> listing a act upon file matching the same prefix and/or suffix if
> supplied. This is the code I use now.

First of all, I made some stylistic changes. I prefer to
"interpolate {$variables} like so" or to use sprintf().

I changed your variable name $file, as there is a built-in function file().
I couldn't say if that actually would conflict or not, because I would never
do that :) Avoiding that type of potential conflict is just a good habit.

To shorten the code, I think you could just test the prefix and suffix
without checking which of them are set. I didn't test your code, but I
imagine your code would also evaluate as you expect, were they blank or
not. Same with the regex here; however, I didn't test this code either.

Hopefully this type of optimization is what you were looking for.
- Kelly


// constant; preferred date format
define('DATE_FMT','F j, Y');

// set file prefix and suffix
$deleteprefix = "";
$deletesuffix = "";

// create regex pattern
$regexpattern = sprintf('/^%s.*%s$/',$deleteprefix,$deletesuffix);

// open folder or die!
$dir_handle = @opendir($rootpath) or
die("Unable to open {$rootpath}: not folder\n");

// loop through files in directory
while ($fname = readdir($dir_handle)) {

   // remove files matching the prefix/suffix, that don't start with dot
   if (preg_match($regexpattern,$fname) && substr($fname,0,1) != '.') {
  $modtime = date(DATE_FMT,filemtime($rootpath.$fname));
  logger(sprintf('Deleted: %s Last Modified: %s',$fname,$modtime));
  unlink($rootpath.$fname); }

}

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] oo question

2004-04-19 Thread Kelly Hallman
Chris,

Apr 19 at 10:33am, Chris W. Parker wrote:
> my question has to do with abstraction (i think that's the word).

I think what you're talking about here is encapsulation. And yes, you are
correct to point out that the second approach allows the more
encapsulation of the object's data. Using methods to set or get the data
stored in the object provides an interface to the object, whereas
accessing the object's properties directly isn't a true interface.

> PROPOSED CHANGE:
> class Customer {
>...
>function initialize_customer($customer_id) {
>// grab data from db
>$this->fname = $...[0]['fname'];
>$this->lname = $...[0]['lname'];
>$this->age   = $...[0]['age'];}

This is perfectly fine, but if you want to use those get/set methods as an 
interface, you're better off not setting the properties as above...

How about something like this:
(also took some liberties with the variable/method names...)

class Customer {

var $res = array();
var $id, $fname, $lname;

function Customer($id=null) {
$id === null || $this->initCustomer($id); }

function firstName($fname=null) {
$fname === null || $this->res['fname'] = $fname;
return $this->res['fname']; }

function lastName($lname=null) {
$lname === null || $this->res['lname'] = $lname;
return $this->res['lname']; }
...
function initCustomer($id=null) {
$id === null || $this->id = $id;
$row = $db->getOne($query); // grab assoc array of db row...
return $this->res = $row; }

function exportCustomer() { return $this->res; }

I think that may better illustrate the benefit of the interface. You can
store the data inside the object, but thanks to encapsulation only the
object itself needs to know how to access or manipulate the data that is
stored inside. As a user of the object, you never need to know what the
internals of the object are. As the developer, you don't need to worry if
you want to change the structure, as long as the interface remains intact.

Since you really don't want to go TOO far with the OO in PHP4, you can 
always store the simple scalar data in the object's properties, and just 
use that as a defacto interface.. for instance $obj->id = 35; is not much 
different from $obj->id(35), and $x = $obj->id; is similar to $obj->id();
Decide which you prefer, but encapsulation is an important OO concept.

My point: it's redundant to have $obj->fname and $obj->firstName(),
and may encourage mixing the way you access the object data from your 
code, which could potentially defeat the purpose of the get/set method.

On that note, you may be interested in the __call(), __get() and __set()
magic methods in PHP5, as they will give you the best of both worlds.
...Among many other nice OO feature improvements in PHP5...

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Re: oo question

2004-04-19 Thread Kelly Hallman
Apr 19 at 11:06am, Chris W. Parker wrote:
> Torsten Roehr <mailto:[EMAIL PROTECTED]>
> > One personal suggestion: you could directly put the code from
> > initialize_customer() into the constructor.
> 
> but i'm thinking that i might, at some point, want to use that method
> after the object has been instantiated. i can't think of a specific
> case, but i'm only imagining that it's possible.

You could conceivably call the constructor as any other method, such as
$obj->Customer(35); ...so, you could collapse it all into a single method.

I think that is not as logical, and you may want to change the
functionality of the constructor later, independent of the method to that
loads the data from the DB, so personally I'd leave it.

Further, I think it's best to keep the constructor as simple as possible,
and try to avoid the temptation of doing too much fancy work there. (Save 
it for a convenient use, like what you have done...)

Reason being, you may want to use the object more generically later.
Perhaps you would write a script that queried the whole user table, and
instantiated many Customer objects.

Sometimes putting too much into the constructor can add overhead if you
want to create lightweight instances of the object for another purpose
that you're not envisioning at the moment.

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Pear Layout question

2004-04-19 Thread Kelly Hallman
Apr 19 at 7:30pm, Chris wrote:
> I would like to be able to give my customers a zip file with my script
> and all the needed pear modules. I've looked over the documentation and
> I did not see anything touching on this.
> 
> PEAR
> --DB
> --HTTP
> --SOAP
> --NET
> ...

As long as the directory containing the PEAR files is in your include
path, and it mimics the same structure as the PEAR directory you have on
the server (where PEAR is installed) you should be good to go.

-- 
Kelly Hallman

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] oo question

2004-04-19 Thread Kelly Hallman
Apr 19 at 3:46pm, Chris W. Parker wrote:
> Kelly Hallman <mailto:[EMAIL PROTECTED]>
> > I think what you're talking about here is encapsulation.
> 
> in that case what is abstraction?

I suppose it's pretty similar, but I believe that encapsulation is the
pedantic term for hiding the data structure behind an object's interface.  
I generally would consider something abstraction when it enables you to
access any number of things from a common interface, such as a database
abstraction layer is an API to interfacing to different RDBMS.

> >> PROPOSED CHANGE:
> >> class Customer {
> >>...
> >>function initialize_customer($customer_id) {
> >>// grab data from db
> >>$this->fname = $...[0]['fname'];
> >>$this->lname = $...[0]['lname'];
> >>$this->age   = $...[0]['age'];}
> 
> i see my code has been run through the kellytron 5000. ;)

Dude, it just kills me to not compact the code, at least in a list post ;)
Python! Python did it to me!

> > class Customer {
> > 
> > var $res = array();
> 
> what does $res stand for? result?

Yeah. Generally, I like compact! :) However, I am consistent throughout my 
code, so it makes sense if you spend enough time there! :)

> > var $id, $fname, $lname;
> > 
> > function Customer($id=null) {
> > $id === null || $this->initCustomer($id); }
> 
> what is the above line equivalent to

Equivalent to:
if ($id !== null) { $this->initCustomer($id); }

The conditional:
if ($id === null) { $this->initCustomer($id); }
could also be written as:
$id === null && $this->initCustomer($id);

I just find that more succinct.

> and why is '$id == null' not sufficient?

Because where $id = 0;
($id ==  null) == true;
due to casting, yet
($id === null) == false;

=== is explicit equality, the operands must also be the same type.
also note that !== vs. != is like === vs. ==

for example:
null == 0 == false == array() == ''
where === would cause all to evaluate false

Doesn't mean it'd be insufficient, but it would allow you to pass a zero
to the method, and differentiate between it and the default value of null.

-- 
Kelly Hallman

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Logic problem

2004-04-20 Thread Kelly Hallman
Apr 20 at 9:55am, Alex Hogan wrote:
> function myselect($array1, $array2){
> $query = "SELECT".foreach($array1 as $flds){ $flds[$i]; }.
> "FROM".foreach($array2 as $tbls){ $tbls[$n]; } ...

Alex, if you merely wish to place the values of an array into your 
query, you might also try doing it this way:

$query = 'SELECT '. implode(', ', $array1).
' FROM '. implode(', ', $array2). ' ... ';

Usually when writing queries, I prefer to use sprintf():

$q = 'SELECT %s FROM %s';
$q = sprintf($q, implode(', ',$array1), implode(', ',$array2));

The more complex the query gets, the easier it is to read using this 
approach. I'm sure some find that debatable. After all, I'm crazy ;)

--
Kelly Hallman

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] SCP a file from my server to another using PHP

2004-05-04 Thread Kelly Hallman
May 4 at 4:25pm, Matt Babineau wrote:
> When I take the same string that I jsut used to scp the file and run it
> using exec, system, passthru it doesn't work!! I'm baffled and was
> hoping someone had successfully done this before.
>  
> $address = www.url.com;
> $value = "foldername";

I assume this is not your actual code, but you'll need quotes:
$address = "www.url.com";
  
>if ($urlStatus == "Stopped") {
> $cmd = "scp /home/dev.site.com/mail_admin/commands/remove
> ".$gs['address'].":/home/www/$value/command";
> echo "  ".$cmd."";
> exec($cmd, $tmp, $rtmp);
> print_r($tmp); echo $rtmp;
> echo "";
>}

Looks like you're trying to execute the command:
scp /src/file www.url.com:/dest/file

I think you'll need to use:
scp /src/file [EMAIL PROTECTED]:/dest/file

However, it's highly likely (as Warren Vail alluded) that the web server 
is running as a different userid, therefore it would be as if another user 
executed the scp command, thereby not accessing your keys.

If that is the case, you may be able to set up a key for the webserver 
user to access the remote account.

An alternative would be to use the -i option to scp to specify the key
file (man ssh). In that case, it's likely that the webserver user would
need permissions to be able to read that key file.

Either solution could be a security issue, if you are on a shared server,
as it might allow other users to use that same key to access the remote
server as well. Proceed with caution!

> TIA for anyone who has done this and knows the answer!!!

Haven't done this, but I think it should work. Hope it helps at least.

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] " in data

2004-06-18 Thread Kelly Hallman
Jun 18 at 12:29pm, Jay Blanchard wrote:
> [snip]
> I have data with "something" in it and when I pull that data and dump it
> into an HTML form I am losing everything that is after the first " .
> Has anyone encountered this before, and have a way to patch it?
> [/snip]
> 
> Yes, we have all encountered it. You need to escape the " character and
> other characters as well. Start here
> 
> http://www.php.net/addslashes
> 
> The manual is your friend

Doesn't help terribly much when putting it into HTML (see Chris' post)...
addslashes() is good for database insertions, but for HTML probably are
looking for something like http://www.php.net/htmlentities

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] OOP methodology{O|T} kinda'

2004-01-30 Thread Kelly Hallman
On Fri, 30 Jan 2004, Jay Blanchard wrote:
> > I would have to disagree. While it may be possible to implement good
> > OOP in C++, it does not nearly implement OOP as well as many other
> > languages. It also has many other design problems that hinder the
> > learning of OOP.
> 
> I respect your opinion and all, but how do you come to this conclusion?
> Which of the "many other languages" implement OOP better?

Python, Ruby...?

Of course, I've never done any OOP in C++. My guess is part of the reason 
he said this is because you've got to learn C++ before you're going to do 
much successful OOP with it. Not exactly a small learning curve.

Other languages dispense with a lot of the formalities found in C++ (a 
good or bad thing, depending on your perspective). I found Python to be a 
great language to learn OOP, since it forces good habits on you.

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] OOP methodology{O|T} kinda'

2004-01-30 Thread Kelly Hallman
On Fri, 30 Jan 2004, Jay Blanchard wrote:
> I'd be curious as to how many cam to PHP from a programming background?
> Likewise, how many start with PHP and go on to other languages? And what
> those languages are either direction?

I started serious coding in perl. When I found PHP, I realized I was 
killing myself trying to do CGI with perl, and quickly migrated. That 
transition was easy, and my life got better.

After a couple of years coding in PHP I made a foray into Python. I
learned OOP with Python and was able to work that knowledge into my PHP
programming easily. Using OO with PHP simplified a lot of problems I'd had
trying to do more complex tasks with a procedural/functional approach.

I still use perl to whip up a sysadmin script here and there, but after 
using Python I began to regard perl as a syntactic mess.

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] auto forms from mysql database

2004-02-02 Thread Kelly Hallman
On Tue, 3 Feb 2004, Justin French wrote:
> So, looks like I'm back to PHP logic.
> 
> I considered that I could store a simple array of required/etc field
> names to which I could check against when building the form from the
> mysql data, but my hope is that someone else has tackled something like
> this in the past, and can offer some advice...

I think your best bet may be to design some sort of object that defines
these tables/forms, that can be extended for each table/form or that
contains the definition and can be serialized somewhere... Doing it that
way would facilitate changing the underlying data source if necessary, and
it seems like a logical architecture.

The idea of autonomous database form creation is interesting, and your 
naming convention ideas are novel, but I have the same issue that you 
apparently do with that, it could come back to haunt you down the road..

Design the object well and it could validate the data automatically or
contain other non-database data such as form headings, help text, etc.

Also hooking this into some kind of form class (I like PEAR's
HTML_QuickForm) may help speed things along...

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Using a perl regex

2004-02-11 Thread Kelly Hallman
On Wed, 11 Feb 2004, Verdon Vaillancourt wrote:
> I thought I might have tried that and just did again.
> 
> I receive the error; Warning :  Delimiter must not be alphanumeric or
> backslash in /server/path/to/functions.php on line 
> 
> I'm not sure if this means I have to escape something in the pattern,
> but will look further.

I think it means you need to put a delimiter around your regex...
Typically you would use slashes (preg_match("/regex/")) but the character
can be other than slash.. i.e. "not alphanumeric or backslash" :)

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] need form array help

2004-03-01 Thread Kelly Hallman
On 1 Mar 2004, Brian V Bonini wrote:
> while ($result = mysql_fetch_array($dbresult_riderlist)) {
> print('' . "\n");
> print(" $result["rider_id"] . '" />' . "\n");
> print(" $result["rider_name"] . '" size="15" />' . "\n");
> print(" $result["rider_license_cat"] . '" size="3" />' . "\n");
> print(" $result["comments"] . '" size="20" />' . "\n");
> print(" $result["image"] . '" size="10" />' . "\n");
> print("Edit:  value=\"edit\" /> Delete:  name=\"edit_rider_action[]\" value=\"delete\" />" . "\n");
> print('' . "\n");

Here's one way of doing this:

for($i=0;$i<$maxrows;$i++) { // whatever your loop..
echo <<


...



EOF;
}

And reading back the form values:
foreach($_REQUEST['chkrow'] as $v) {
$title = $_REQUEST['title'][$v];
$mode = $_REQUEST['mode'][$v]; // 'edit' or 'delete'
}

Adjust to your particular situation...

--Kelly

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Return value efficiency question

2004-03-09 Thread Kelly Hallman
Consider this method:

function xyz() {
return $this->data = unserialize($this->serial); }

A few assumptions:
- Resultant data large enough to warrant discussion of efficiency
- I always want to store the unserialized data into the object
- The return value is only needed sometimes

If I only need to grab the return value on occassion, what is the 
overhead of returning the value, if it's discarded most of the time?

Example:
$obj->xyz(); // method returns data, but nothing is done with it

Same difference?
Or better to break this out and only use return when needed?

Appreciate any expert responses. I don't know enough about the internals 
of PHP to know the implications of this... thank you!

--Kelly

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Are $_POST and $_GET interchangable?

2004-03-10 Thread Kelly Hallman
Mar 10 at 9:45am, Five wrote:
> If I have some snap and I want to see some other employee's info I can
> then type it into the URL
> http://www.foo.com/employee.php?eid=bstreisand
> 
> The rules for usage come down to this - A little common sense goes a
> long way. There are really no specific rules.

On that note, something to keep in mind is that GET variables (being part
of the URL) are written to server logs. Depending on the data being
passed, this could be a security issue (especially in a shared hosting
environment where untrusted users may have access to the logs).

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] What's the use in OOP?

2004-03-29 Thread Kelly Hallman
Mar 29 at 5:25pm, Stephen Craton wrote:
> I used OO in my chat script (can be found at http://php.melchior.us) but
> it really seemed like a waste since it was such a small basic script. I
> never really find myself re-needing code except for database
> connectivity and calling the database and stuff like that.

If you take away your class statements, I'd wager that this looks a lot
like it would had you just done it without OOP. It's a design and
organization issue. What you have probably works, but there is so much
more you could do if you spent your time designing objects in the proper
way. Your database connection object is a more logical start...

I think a chat app could easily be something more than just 'functional' 
if you start thinking about the tangible concepts you'd have in some kind 
of chat application-- users, chat sessions, messages. Then later say you 
want to add support for other types of "events".. then you think, hey, an 
event is just a different type of message, just extend the message object.

When you've got a bunch of disorganized functions that work in specialized
ways, you are adding on or reworking huge sections of code every time you
want to add or change something. With well designed objects, the worst
case scenario is you write a new object.

I think there is a bit of what I consider an efficiency myth in regards to
OOP in PHP. Most agree that the OO implementation in PHP is not robust.  
However, most people that rely on this assertion do not usually understand
leveraging OO and also most do not write excellent non-OO code. :)

If nothing else, getting a solid handle on the benefits of OOP can only
make your code better, even if you choose not to use it in every situation
(which most would suggest against in PHP, anyway).

There IS something to OOP! Unfortunately, it's difficult to learn through 
examples of car stereo panels or different types of fruit or trees
(though they do make perfect sense in hindsight).

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] What's the use in OOP?

2004-03-29 Thread Kelly Hallman
Mar 29 at 3:23pm, Chris Shiflett wrote:
> > I think there is a bit of what I consider an efficiency myth in
> > regards to OOP in PHP. Most agree that the OO implementation in PHP
> > is not robust.
> 
> It's much better in PHP 5, although a lack of robustness is not how I
> would personally describe PHP 4's shortcomings.

Considering that OO is mostly a convenience for the coder, I just meant
robustness of the implementation in a general sense, nothing specific...

> > However, most people that rely on this assertion do not usually
> > understand leveraging OO and also most do not write excellent non-OO
> 
> Perhaps, but I would say that most people who make this assertion
> understand OO. The performance penalty is not a myth. Just as templating
> incurs a performance penalty, so does OO. The reward can be worth it, of
> course, in terms of organization and ease of use.

I meant most people that rely on this assertion, to avoid learning OO.  
If you have other reasons for not using OO, then great.. but when the
subject is "what's the use of OOP?" then I think we're talking about two
different groups of people...

> The same argument extends further, since I would rather write some things
> in PHP or Perl than than C. I know C is faster, but I'm usually more
> interested in making things easier on myself.

Precisely! The efficiency myth was meant only in the sense that it's a
myth to think simply avoiding (delving into) OOP because "I've heard that
it's slow in PHP" automatically means you're being more efficient. It's
not the prime language for OOP but I find that when it all balances out,
for web apps in PHP, OO offers an attractive price/performance ratio...

(can't wait for PHP5)

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Tricky array question

2004-04-01 Thread Kelly Hallman
Apr 1 at 8:13pm, Merlin wrote:
> I am trying to get continent and country info out of an xml file. There
> is a continent element to each country element. Now I do have an array
> with the continent info and one with the country info. The goal is to be
> able to output all countries sorted after continents.
>
> $results[]->countryContinent
> $results[]->countryName

First, although this does work, I don't know if it's what you want to do.
You'll end up with a structure like this:

Array (
[0] => stdClass Object
( [countryContinent] => North America )
[1] => stdClass Object
( [countryName] => Canada ) )

Not very useful, as you've found.

> I tryed to group those values, to do array searches and more, but somehow
> it looks like that there must be a way more easy way to do this.

I think this is along the lines of what you want to do:

$continent = 'North America';
$landmass[$continent][] = 'Canada';
$landmass[$continent][] = 'United States';
$landmass[$continent][] = 'Mexico';

$continent = 'Asia';
$landmass[$continent][] = 'Japan';
$landmass[$continent][] = 'China';
$landmass[$continent][] = 'Korea';

// sort continents then countries
ksort($landmass); // use ksort() to sort by key
foreach($landmass as $conti => $cntry) { sort($landmass[$conti]); }

print_r($landmass);

There's your array, just loop over it as you like, to do your output.
If you're reading an XML file, you might look into PEAR, which has 
packages for parsing and building data structures of XML data.

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] smarty

2004-04-06 Thread Kelly Hallman
Apr 6 at 5:33pm, Angelo Zanetti wrote:
> hi all has anyone used smarty before? what do you think of it? I think
> it's pretty nice to seperate your script (code) from your design.
> i would like to hear your comments and if you have any alternatives

There are a lot of templating systems for PHP, but I chose Smarty because 
it seemed the most feature-laden, and likely to have continued support.
I wanted to standardize on something, so I went for the most ubiquitous.
Really, I couldn't be happier with it in every regard.

At first it may seem like more than you need, but continue working with it
and you'll find new design strategies that take you further than you ever
thought you'd go. It's one of those things you start using and never look
back. I use it on almost every project now, even small ones.

There are the naysayers who complain it's too bloated for basic work,
but I think the powerful benefits far outweigh any performance issues.
I've never felt like it was slow or too much for a given task.

Get yo' template on!
--Kelly (another Smarty fan)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] smarty

2004-04-06 Thread Kelly Hallman
Apr 6 at 2:43pm, Chris de Vidal wrote:
> Given that scripts are compiled the first time they're ran, you'll
> never* notice the bloat and never lack performance; it's the same as
> real PHP code and can be optimized with a caching engine like Zend.

Certainly. However, the Smarty compiler is about 2200 lines of code, and
the Smarty class itself (which does load every time) is about 2000. Both
figures rounded up, and both files contain heaps of comments.  

Still, many people consider this bloat, if they're merely wanting to
search and replace a couple of values on an HTML template.

Those people are not really leveraging a template system, but if that's
all you wanted to do--ever--I can see why the additional overhead would be
undesirable. After all, a simple search and replace for a few values
doesn't require 4000 lines of code parsed (or 2000, after compilation).

> OK so you will notice it the first time and if you make any changes

Yes, and whenever your cached/compiled template has expired.

> For our next site, she'll mock up everything in Front Page how she wants
> it to look then I'll add template tags and business logic.  Whee!
> Separation of code from design, at last!

Working with others is one of the main benefits of a templating system. It 
doesn't matter then if it's FrontPage code or not, at least you, as the 
developer, don't have to muck with it. And it's easier to clean up later.

> It will be tempting to put all logic in the PHP but you might need some
> logic in the template; for example, we have a level check...

I'd go a step further and suggest using as much logic in the template as
possible. In a basic sense, it's display logic, not application logic.

> Instead, I put something like this in the template:
> {if $level > 2}{bio}{/if}

Again, take it a step further and you may just load up a $User object (of 
your design) within your PHP code. Then in the template, you could use:

{if $User->hasPermission('write')} ... {/if}

When you start thinking like this, your PHP logic gets very slim and easy 
to read and maintain. This is the goal and benefit of templating.

A common reaction when starting to work with Smarty is "you mean I need to
assign each variable into the template one-by-one?!" On a certain level
this is true. But as illustrated above, you can also pass arrays, objects
and other complex data structures into your template.

It becomes especially powerful when working on a larger web app. You
needn't assign your values into the template from each PHP page. You can
make a boilerplate include and assign common variables as references:

// boiler.php
$pt = new Smarty;
$pt->assign_by_ref('User',$User);

// mypage.php
require "boiler.php";
$User->doStuff();
$User->admin = true;
$pt->display('template.tpl');

So you can attach references right off the bat in an include, then every
time you use that include, you've already got things assigned and can
change them all you want before displaying, without additional assignment.

Going even one step further (the beauty of Smarty: always another level),
just extend the Smarty object itself. Then, instead of making all your
templates includes other templates (such as a header or a footer), you can
make your overall page be a template, and the extended Smarty object can 
be given extra functionality to control the page:

{* MyPage.tpl -- Smarty template for the entire page *}
...header...
{include file=$content}
...footer...

// mypage.php -- extended Smarty object
class MyPage extends Smarty {
   var $tmpl = 'MyPage.tpl';
   function render($x) {
  $this->assign('content',$x);
  $this->display($this->tmpl); } }

// actualphpcode.php -- called by the browser
$pt = new MyPage;
$pt->render('pagecontent.tpl');

Now, is Smarty awesome, or what? :)
--Kelly

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] smarty

2004-04-07 Thread Kelly Hallman
Apr 8 at 10:26am, Justin French wrote:
> PHP itself is a great templating language :)
> 
> 
> 
>  
> 
> 
> '>
> 

Uhhh, yeah--that's not a templating, that's called spaghetti code :)

You get the concept. Smarty, as you know, basically takes a Smarty
template and writes PHP code similar to what you've done above, then
writes out the .php file, and includes it when you render your template.
So you'd get nearly the same effect by writing the PHP as a separate file
and including it as your last step, and it acts as your display logic.

That may be acceptable to you, as a PHP programmer. If you're the only one
who ever needs to modify your templates then that's great, more power to
you. I'm sure that you would have no problem having many levels of nesting
all over the place and not screwing anything up. So be it. But that's you.

I guarantee another person not as adept at PHP will screw that code up,
and there is less potential for that with a Smarty template. If you know
PHP as well as yourself, it should be plain to see how Smarty is just a
wrapper over PHP that makes templates easier to build and maintain.
For a designer or non-coder, Smarty will be easier to learn than PHP.
 
Unless your needs never exceed the very basics like you have demonstrated
above, you'll be hosed when another person needs to modify your template.  
Which goes back to a templating truism never in dispute: if this is all
you want templating for, it's six of one, half a dozen of the other.

However, there are practical limitations on what you can easily accomplish
with this approach, and Smarty addresses those issues. And you're worse
off if you invest a lot into building your sites this way, and then
realize you need some better templating strategies later.

> You can still separate your logic from your presentation, template 
> designers can still use quick, simple "tags" to include code, and the 
> upside is that people familiar with PHP don't need to learn ANOTHER 
> language (that's what Smarty is) -- they can dive straight in.

You can consider it it's own language, but really it's more like PHP with
different formatting. Which is why it's different than what you're doing
above--it's designed to facilitate templating. Your method is just poking
in variables and PHP into inline'd HTML. It works, but you're missing some
of the power of Smarty if you think that's all it's good for.

> The question is, do you want to give your templater designers full 
> access to the power of PHP, or not.

In other words: are your template designers already good PHP programmers?
It's not just hype, it solves real problems, even if you don't have them.

--Kelly

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] smarty

2004-04-07 Thread Kelly Hallman
Apr 7 at 10:01pm, Robert Cummings wrote:
> Smarty is a bit of a hack too... why do I need to declare my templates
> within the PHP code? If I'm an HTML designer I'd like to create a new
> page, include templates, use some data that's been made available and
> have it all in the template. I sure as heck wouldn't want to have joe
> programmer edit the main page, add support for importing my template.

I like Smarty because it solved many of the problems I was having trying
to tackle the problems manifest when using no templating strategy.

Actually, InterJinn has been on my radar screen for a while now, and 
thanks to your timely plug, I think I'll try it out and see how it 
compares. Incidentally, your posts on the Smarty list are what had me 
considering InterJinn in the first place.. how subversive of you! :)

I'm not married to Smarty, I just think that it's got a lot more to offer
than many PHP coders give it credit for after a mere cursory evaluation.  
Further, many of the people who shun templating systems aren't really
working with web applications as much as simple PHP scripts, where
templating solutions are much less necessary.

I think we're on the same side. Perhaps I just haven't yet seen the light.  
I'll give InterJinn a go. I hope it's all you say it is. One thing we can
both agree on is that templating is not inherently redundant with PHP.

--Kelly

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] smarty

2004-04-07 Thread Kelly Hallman
Apr 7 at 10:22pm, John W. Holmes wrote:
> > Uhhh, yeah--that's not templating, that's called spaghetti code :)
> 
> +1 - Use of buzzword

Right about here I could sense where this was going I don't know, what
would you call it? Is there a non-buzzword term you'd be happier with?  
That term predates PHP by a number of years, so I'm not sure about buzz...

> > For a designer or non-coder, Smarty will be easier to learn than PHP.
> 
> You must work with some real idiots.

Sigh... you must work with some really lousy designers!

> You can teach them to write {$variable} but you can't teach them to
> write  ?? Give your people some credit. If they can learn
> {section name="foo" loop=2 show=TRUE}{/section}, then they can learn
> for($x=0;$x<2;$x++){ }, can't they??

Sure, they could. However, take a look at all the newbie questions on this
list. Maybe you've got time for all that hand holding.. but Smarty is a
lot closer to HTML, which many of them already know.

> I'm sorry, but if Smarty takes your "template" and turns it into code 
> like the example above, EXACTLY what "limitations" are you going to run 
> into using the method above that Smarty solves?

How about the limitation of lack of infinite time? Seriously man, it's a
tool. If you think that I was claiming Smarty auto-magically did things
you couldn't do with PHP, you need to pay more attention...

> Fight it all you want, but PHP is a templating engine, too. That was 
> it's original purpose. And again, what "power" of Smarty are we missing 
> if Smarty just turns the template back into PHP code, anyhow?

Fight what? If you call inline code and variables a templating engine, I
can see why you don't get it. PHP can serve a templating purpose, but it
doesn't greatly facilitate that out of the box. It's not a strategy.

I don't want to get into a tit-for-tat, but there are a lot of things that
Smarty makes much easier and more flexible than coding straight PHP:

The ease of developing and applying different types of template plugins,
the ability to dynamically attach arbitrary functions as template plugins,
extending the Smarty class to encapsulate methods to control more complex 
template functionalities.. the list goes on..

Please read the next sentence twice. You can do it all with plain PHP, but
I can do it much faster with Smarty, which is merely a TOOL.

> > In other words: are your template designers already good PHP programmers?
> > It's not just hype, it solves real problems, even if you don't have them.
> 
> You can either teach your designers the Smarty language or you can teach 
> them PHP. Which one will set them up for success?

Again, very much not the point.

> Now, all that being said, I am a fan of Smarty and use it in some
> applications. But, there's no reason you can't use straight PHP and
> achieve the same results by simply separating presentation logic from
> your code.

It's clear you're just trying to be antagonistic, so I won't beleaguer the
point. I have a strong understanding of PHP, and I myself find Smarty
easier to work with from a template design standpoint.

Please feel free to call me a total idiot, question my intelligence,
belittle me or the people I work with, and other side topics relating to
the technical merits of Smarty or the use of templating systems.

I found it really educational and enriching.
Thanks for your contribution.


PS: I think this is tired at this point; thank you to Justin for a
thoughtful response that reassured me it was still a discussion. I realize
that many PHP 'experts' (let's call them) may find different solutions
that suit them differently. People have different levels and different
needs. I personally like Smarty, and Smarty was the original topic of the
thread. I'm open to ideas, but going back to mixing PHP and HTML is not a
new idea nor a true templating system, and there are valid reasons I
sought out a more comprehensive approaches after doing it that way for
many years. I found much benefit in Smarty, and hope others will too.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] smarty

2004-04-08 Thread Kelly Hallman
Apr 8 at 7:38am, Aaron Wolski wrote:
> I don't think this thread is tired. As someone who is about to dive into
> learning templating more than what I do now...

Tired in the sense that it had degenerated to a personal level that was 
uncalled for and off-topic. The merits of templating are never tired!

> I'll be frank with this next comment and say to you, Kelly, that it was
> fine and dandy for you to be antagonistic and demeaning with your tone
> towards Justin French when he commented that PHP, itself, IS a
> templating engine, but when John turned the tables in regards to those
> remarks made you get very defensive and ornery as illustrated in this

Here again, because I think it had been taken to a level that did not add
anything to the debate at hand, and was antagonistic for the sake of
antagonism. I was hardly trying to disrespect the point that Justin was
making, in fact I had no disagreement with the approach, other than that
it sold the concept of templating short by claiming that there is no
difference. If there was no difference, Smarty would not exist.

I think it is valid and important to understand that Smarty buys you
nothing you can't get with PHP. However, claiming that it's exactly the
same to use straight PHP, says to me that Smarty is either not being 
leveraged or it's true possibilities are not being realized.

There is a difference between a conscious choice by someone who is an
experienced PHP developer not to use Smarty, and someone who merely
doesn't see the leverage or purpose of the tool. Pedantic debates like
this surface regularly on topics such as OOP in PHP, to the detriment of
those looking for answers to problems they legitimately want to solve.

The reason this is frustrating is not because people should not have 
opinions or that there is nothing to be gained by expressing them. It's 
much different to say, for instance, "I don't use Smarty because for my 
purposes it's the same difference to just use a straight PHP approach" and 
to say "PHP already does exactly this, and thus Smarty is pointless."

And thank you for your guidance in regards to my conduct. Apparently you
also read the same things INTO my message to Justin, and thus it was okay
for a third person to take it to a personal level that was out of line and
when I merely respond to that unprovoked attack, you give me the lecture.

If someone has an issue with my tone, fine. I think that's a perception or
communication issue that can be dealt with by offline clarification, or
any number of other approaches. Going off the handle is not an appropriate
response, and I think even in my "defensive" response I showed Mr. Holmes
a level of decorum that was completely absent in his abusive message.

I see a lot of extremely snide messages on here, and yet, I posted an
opinionated, on-topic message that did not disrespect anyone--yet managed
to raise the dander of a small group--it's then ok with you if some guy
lets go with personal invective. But not okay for me to respond. Get real.

> I want to learn more about Smarty and it's obvious we have some great
> sources here to do so. Let's get past the snide remarks and keep focused
> on educating and discussing the merits of Smarty (or another templating
> engine) so that we all benefit.

Yes, PLEASE! I regretted having to send that message, but I did so for the
same reason I responded to this one. It was personally addressing me.

Learn to discern the difference between a passionate debate and personal
attacks (not that yours was an attack, but it was unnecessary to come in
and try to call the shots on an off-topic issue that was already dead).

Please, let's get on with the relevant discussion!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Serializing objects and storing them is sessions [fixed]

2004-04-09 Thread Kelly Hallman
Apr 9 at 1:44am, Jason Giangrande wrote:
> Jason Giangrande wrote:
> > I'm having a problem unserializing objects that are passed from page to 
> > page with sessions.  Registered globals is disabled so I am using the 
> > $_SESSION array to store session variable
> > 
> > When I var_dump() $_SESSION it appears to be a string representation of 
> > the object.  However, when I try to unserialize() it and store it in 
> > $auth the value is bool(false) and not an object.
> > 
> > Can anyone tell me what I am doing wrong?
> 
> Don't I feel stupid now.  I have solved my problem.  I had written a
> __sleep() function that I had forgotten about, and as it turns out, it
> was breaking things.  Not really sure why.  It was just creating the
> array of object properties to be serialized.  Commenting it out fixes
> the problem I was having.

You shouldn't serialize() objects prior to assign to a session variable.  
The default session handler automatically serializes the data. Assigning a
serialized object value to a session just adds redundancy and overhead. 

The only caveat: the class must be defined prior to session_start(), for
the same reason a class needs to be defined prior to unserializing.
http://www.php.net/manual/en/language.oop.serialization.php

--Kelly

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Serializing objects and storing them is sessions [fixed]

2004-04-09 Thread Kelly Hallman
Apr 9 at 11:12am, Jason Giangrande wrote:
> > You shouldn't serialize() objects prior to assign to a session variable.  
> > The default session handler automatically serializes the data. Assigning a
> > serialized object value to a session just adds redundancy and overhead. 
> 
> Actually, only if you create the session with session_register() are 
> they serialized automatically.  If you simply assign an object to the 
> $_SESSION array it must be serialized manually.

When writing the above response, I had noted the documentation mentioned
something to this effect. I believe this is incorrect or ambiguous.

Try it without serializing, it works.

After running some tests, I can't speculate on the exact operation, as it
appears that the session handler may be 'manually' serializing any objects
before serializing the session data, as opposed to this being inherent in
the handler's serializing of the session data.

The point is, it's not necessary to manually serialize() the object.  
Regardless of the semantics, it happens transparently. Advantageous
because then you can just access the object directly via the session
variable, without needing to convert it in and out every time.

-- 
Kelly Hallman

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] splitting string

2004-11-16 Thread Kelly Hallman
Nov 16 at 12:00pm, Chris W. Parker wrote:
> > Also, is there actially better way to do this then adding \n between
> > strings? (e.g. store form fields name, address, city, state, zip,
> > phone, email as a one string in db and later pull them from DB and
> > split them back?)
> 
> Yes.
> $string = "$string1|$string2|$string3|$string4|$string5";
> $string_back = explode("|", $string);

I think tabs are a better delimiter since they can't really be input into
a text field in a typical form/browser, and they have even less relevance
to most text input. (I can't think of why a pipe would be there either,
but it would be easy to type one in, even on accident, therefore you'd
need to sanitize the input to assure you didn't have unexpected
delimiters; probably should anyway regardless of delimiter).

Also, remember list() when unpacking an array to variables:
list($address, $city, $state, $zip, $country) = explode("\t", $input);

I agree, however, that this is an undesirable way to store data in an 
RDBMS. Still, it's better than serializing and unserializing... :)

On that note, I think this should only be used for data that is NEVER
intended to be queried, but may be usefully extracted on SELECTed records. 
And we know the wisdom of assuming something will NEVER be necessary! :)

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php