php-general Digest 9 Feb 2008 11:36:12 -0000 Issue 5283

Topics (messages 268978 through 269002):

php 4.x + mysql 5
        268978 by: ahlist
        268980 by: Jim Lucas
        268996 by: ahlist

issues with calling methods twice in a row
        268979 by: nihilism machine
        268982 by: Jim Lucas
        268983 by: Nathan Nobbe
        268984 by: nihilism machine
        268985 by: Nathan Nobbe
        268986 by: Jochem Maas

Re: Name of variable to string [SOLVED]
        268981 by: tedd
        268987 by: Daniel Brown
        268988 by: Jim Lucas
        268989 by: Jochem Maas
        268990 by: tedd
        268991 by: Robert Cummings
        268992 by: tedd
        268993 by: tedd

Order directory output
        268994 by: Pastor Steve
        268995 by: Jim Lucas
        268997 by: Shawn McKenzie
        268998 by: Nathan Nobbe
        268999 by: Nathan Nobbe
        269000 by: Paul Scott
        269002 by: Børge Holen

Posting Summary for Week Ending 8 February, 2008: [EMAIL PROTECTED]
        269001 by: PostTrack [Dan Brown]

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
Hi,

I have a client who requires php 4.x with mysql 5 (cannot use php 5
for this project).

Can anyone confirm that it is possible to use this combination without
setting mysql to use old-style passwords.

I have a clean php 4.4.7 compile but it still shows the old mysql lib
version. I can't find where it is picking that up at. Is it just built
into the php sources that way?

Thanks.

--- End Message ---
--- Begin Message ---
ahlist wrote:
Hi,

I have a client who requires php 4.x with mysql 5 (cannot use php 5
for this project).

Too bad...


Can anyone confirm that it is possible to use this combination without
setting mysql to use old-style passwords.

Not sure


I have a clean php 4.4.7 compile but it still shows the old mysql lib
version. I can't find where it is picking that up at. Is it just built
into the php sources that way?

Yes, it is included with the php source. If you want it to use newer libs, then download the devel packages for the newer mysql version and at compile time, point the configure script for php use the newer devel libs instead. That should be all that is needed.


Thanks.



--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare

--- End Message ---
--- Begin Message ---
On Feb 8, 2008 4:16 PM, Jim Lucas <[EMAIL PROTECTED]> wrote:
> ahlist wrote:
> > Hi,
> >
> >
> > I have a clean php 4.4.7 compile but it still shows the old mysql lib
> > version. I can't find where it is picking that up at. Is it just built
> > into the php sources that way?
>
> Yes, it is included with the php source.  If you want it to use newer libs, 
> then
> download the devel packages for the newer mysql version and at compile time,
> point the configure script for php use the newer devel libs instead.  That
> should be all that is needed.
>

Good idea! I may end up doing that.

My goal is to position this so that a move to php5 would work and not
be stuck with a bunch of old-style mysql passwords that need updated
by users (since the original passwords are not retrievable of course
for conversion unless I store plain text copies, which I do not want
to do).

Thanks for your input.

--- End Message ---
--- Begin Message --- i have a method called CreateUser() which is public and takes 5 variables as its data, then adds them to a db. it only executes the first method not the other although its all the same but the variable.

ex:

$auth = new auth();
$auth->CreateUser("fake email", 1, "fake name", 4);
$auth->CreateUser("fake email", 2, "fake name", 4);
$auth->CreateUser("fake email", 3, "fake name", 4);
$auth->CreateUser("fake email", 4, "fake name", 4);
$auth->CreateUser("fake email", 5, "fake name", 4);

any ideas? only the first method gets executed?

--- End Message ---
--- Begin Message ---
nihilism machine wrote:
i have a method called CreateUser() which is public and takes 5 variables as its data, then adds them to a db. it only executes the first method not the other although its all the same but the variable.

Here you say that the method takes five (5) variables.


ex:

$auth = new auth();
$auth->CreateUser("fake email", 1, "fake name", 4);
$auth->CreateUser("fake email", 2, "fake name", 4);
$auth->CreateUser("fake email", 3, "fake name", 4);
$auth->CreateUser("fake email", 4, "fake name", 4);
$auth->CreateUser("fake email", 5, "fake name", 4);

But here, you are only putting 4 variables in the method call.

Are you missing something that is required?  The fifth field perhaps?


any ideas? only the first method gets executed?



--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare

--- End Message ---
--- Begin Message ---
On Feb 8, 2008 4:10 PM, nihilism machine <[EMAIL PROTECTED]> wrote:

> i have a method called CreateUser() which is public and takes 5
> variables as its data, then adds them to a db. it only executes the
> first method not the other although its all the same but the variable.
>
> ex:
>
> $auth = new auth();
> $auth->CreateUser("fake email", 1, "fake name", 4);
> $auth->CreateUser("fake email", 2, "fake name", 4);
> $auth->CreateUser("fake email", 3, "fake name", 4);
> $auth->CreateUser("fake email", 4, "fake name", 4);
> $auth->CreateUser("fake email", 5, "fake name", 4);
>
> any ideas? only the first method gets executed?


whats going on inside CreateUser(), have you tried tracing the logic?
are the successive calls raising any errors?

-nathan

--- End Message ---
--- Begin Message ---
that was just an example. yes they both provide 5 input variables.

On Feb 8, 2008, at 4:18 PM, Jim Lucas wrote:

nihilism machine wrote:
i have a method called CreateUser() which is public and takes 5 variables as its data, then adds them to a db. it only executes the first method not the other although its all the same but the variable.

Here you say that the method takes five (5) variables.

ex:
$auth = new auth();
$auth->CreateUser("fake email", 1, "fake name", 4);
$auth->CreateUser("fake email", 2, "fake name", 4);
$auth->CreateUser("fake email", 3, "fake name", 4);
$auth->CreateUser("fake email", 4, "fake name", 4);
$auth->CreateUser("fake email", 5, "fake name", 4);

But here, you are only putting 4 variables in the method call.

Are you missing something that is required?  The fifth field perhaps?

any ideas? only the first method gets executed?


--
Jim Lucas

  "Some men are born to greatness, some achieve greatness,
      and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
   by William Shakespeare


--- End Message ---
--- Begin Message ---
On Feb 8, 2008 4:25 PM, nihilism machine <[EMAIL PROTECTED]> wrote:

> that was just an example. yes they both provide 5 input variables.


well theres something preventing successive calls from doing what you
expect.  php has no issue in calling the same instance method successively,
which you could verify with a simple test case.

-nathan

--- End Message ---
--- Begin Message ---
nihilism machine schreef:
i have a method called CreateUser() which is public and takes 5 variables as its data, then adds them to a db. it only executes the first method not the other although its all the same but the variable.

ex:

$auth = new auth();
$auth->CreateUser("fake email", 1, "fake name", 4);
$auth->CreateUser("fake email", 2, "fake name", 4);
$auth->CreateUser("fake email", 3, "fake name", 4);
$auth->CreateUser("fake email", 4, "fake name", 4);
$auth->CreateUser("fake email", 5, "fake name", 4);

any ideas? only the first method gets executed?

no-one can smell the problem with the info you gave.

what is the code for createUser()?
what is does you error log contain?
are you displaying errors? (you should probably do so in a dev environment)
are the 2nd + subsequent calls being made and nothing is entering
in the DB OR are the 2nd + subsequent calls not occuring at all?



--- End Message ---
--- Begin Message ---
At 10:31 AM -0500 2/8/08, Daniel Brown wrote:
 > On Feb 8, 2008, at 10:14 AM, tedd wrote:

 > Hi gang:
 >
 > From a variable with the name of $this_variable -- how do I get a
 > > string 'this_variable' ?

    What Tedd means is this:  ;-P

BINGO! We have a winner!

For those of you who want to know what I'm doing with the solution, please review:

 http://www.webbytedd.com/bbbb/var-string/index.php

Warning: Geek meters should be worn at all times and exposure should be limited. All code is shown.

The "problem" that I was seeking a solution for was simply an easier way to grab POST and GET variables and place them into SESSIONs while keeping the most current values current.

I'm a little disappointed in the solution because I wanted the statements to be:

$post_var = sessionize_post($post_var);
$get_var = sessionize_get($ger_var);

But, the function provided by Daniel (and found in the literature) would not work from within my session_post and session_get functions -- I think it's probably something to do with the scope of the variable.

In any event, I had to alter the calls to:

$post_var = @sessionize_post($post_var, vname($post_var)); $get_var = @sessionize_get($get_var, vname($get_var));

You see, there can be reasons why someone would want to know the variable's name.

Thanks Daniel and to all who commented.

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
On Feb 8, 2008 4:17 PM, tedd <[EMAIL PROTECTED]> wrote:
> At 10:31 AM -0500 2/8/08, Daniel Brown wrote:
> >  > On Feb 8, 2008, at 10:14 AM, tedd wrote:
> >>
> >>  > Hi gang:
> >>  >
> >>  > From a variable with the name of $this_variable -- how do I get a
> >  > > string 'this_variable' ?
> >>
> >     What Tedd means is this:  ;-P
>
> BINGO! We have a winner!
>
> For those of you who want to know what I'm doing with the solution,
> please review:
>
>   http://www.webbytedd.com/bbbb/var-string/index.php
>
> Warning: Geek meters should be worn at all times and exposure should
> be limited. All code is shown.
>
> The "problem" that I was seeking a solution for was simply an easier
> way to grab POST and GET variables and place them into SESSIONs while
> keeping the most current values current.
>
> I'm a little disappointed in the solution because I wanted the
> statements to be:
>
> $post_var = sessionize_post($post_var);
> $get_var = sessionize_get($ger_var);
>
> But, the function provided by Daniel (and found in the literature)
> would not work from within my session_post and session_get functions
> -- I think it's probably something to do with the scope of the
> variable.
>
> In any event, I had to alter the calls to:
>
>      $post_var = @sessionize_post($post_var, vname($post_var));
>      $get_var = @sessionize_get($get_var, vname($get_var));
>
> You see, there can be reasons why someone would want to know the
> variable's name.
>
> Thanks Daniel and to all who commented.

    And thank you for putting credit where it was really due.  I knew
I had gotten that code a couple of years ago from somewhere, but
couldn't remember where.  I hadn't written it, only modified it.  I'm
going to update my code now to put the "thanks to" section in there to
the person who deserves the credit: Lucas Karisny (lucas dot karisny
at linuxmail dot org).

    I had tried to find that each time I referenced the code or used
it myself, but never did.  If only I had R'd TFM.  :-\

-- 
</Dan>

Daniel P. Brown
Senior Unix Geek
<? while(1) { $me = $mind--; sleep(86400); } ?>

--- End Message ---
--- Begin Message ---
tedd wrote:
At 10:31 AM -0500 2/8/08, Daniel Brown wrote:
 > On Feb 8, 2008, at 10:14 AM, tedd wrote:

 > Hi gang:
 >
 > From a variable with the name of $this_variable -- how do I get a
 > > string 'this_variable' ?

    What Tedd means is this:  ;-P

BINGO! We have a winner!

For those of you who want to know what I'm doing with the solution, please review:

 http://www.webbytedd.com/bbbb/var-string/index.php

Warning: Geek meters should be worn at all times and exposure should be limited. All code is shown.

The "problem" that I was seeking a solution for was simply an easier way to grab POST and GET variables and place them into SESSIONs while keeping the most current values current.

I'm a little disappointed in the solution because I wanted the statements to be:

$post_var = sessionize_post($post_var);
$get_var = sessionize_get($ger_var);

But, the function provided by Daniel (and found in the literature) would not work from within my session_post and session_get functions -- I think it's probably something to do with the scope of the variable.

In any event, I had to alter the calls to:

$post_var = @sessionize_post($post_var, vname($post_var)); $get_var = @sessionize_get($get_var, vname($get_var));

You see, there can be reasons why someone would want to know the variable's name.

Thanks Daniel and to all who commented.

Cheers,

tedd


So, how is this any better then just doing this

$_SESSION = array_merge(array_merge($_SESSION, $_POST), $_GET);

If I replace the two calls to sessionize_*() with the above line, I get the same results. Not sure what I am missing.

--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare

--- End Message ---
--- Begin Message ---
Daniel Brown schreef:
On Feb 8, 2008 4:17 PM, tedd <[EMAIL PROTECTED]> wrote:
At 10:31 AM -0500 2/8/08, Daniel Brown wrote:
 > On Feb 8, 2008, at 10:14 AM, tedd wrote:
 > Hi gang:
 >
 > From a variable with the name of $this_variable -- how do I get a
 > > string 'this_variable' ?
    What Tedd means is this:  ;-P
BINGO! We have a winner!

For those of you who want to know what I'm doing with the solution,
please review:

  http://www.webbytedd.com/bbbb/var-string/index.php

Warning: Geek meters should be worn at all times and exposure should
be limited. All code is shown.

The "problem" that I was seeking a solution for was simply an easier
way to grab POST and GET variables and place them into SESSIONs while
keeping the most current values current.

I'm a little disappointed in the solution because I wanted the
statements to be:

$post_var = sessionize_post($post_var);
$get_var = sessionize_get($ger_var);

But, the function provided by Daniel (and found in the literature)
would not work from within my session_post and session_get functions
-- I think it's probably something to do with the scope of the
variable.

In any event, I had to alter the calls to:

     $post_var = @sessionize_post($post_var, vname($post_var));
     $get_var = @sessionize_get($get_var, vname($get_var));

I don't see why this has to be so convoluted - it would be a heck of
a lot easier to do it with a string:

$post_var = @sessionize_post('post_var');

so why exactly is that not an option (or good idea)?


You see, there can be reasons why someone would want to know the
variable's name.

Thanks Daniel and to all who commented.

    And thank you for putting credit where it was really due.  I knew
I had gotten that code a couple of years ago from somewhere, but
couldn't remember where.  I hadn't written it, only modified it.  I'm
going to update my code now to put the "thanks to" section in there to
the person who deserves the credit: Lucas Karisny (lucas dot karisny
at linuxmail dot org).

    I had tried to find that each time I referenced the code or used
it myself, but never did.  If only I had R'd TFM.  :-\


--- End Message ---
--- Begin Message ---
At 10:42 PM +0100 2/8/08, Jochem Maas wrote:
$post_var = @sessionize_post('post_var');

so why exactly is that not an option (or good idea)?

It IS an option -- and that's what I was doing (except for the suppress error) via this:

$post_var = sessionize_post('post_var');

I just wanted to make it simpler and do this:

$post_var = sessionize_post($post_var);

But, it turned out to be much more involved. It's just an adventure in key punching.

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
On Fri, 2008-02-08 at 16:51 -0500, tedd wrote:
> At 10:42 PM +0100 2/8/08, Jochem Maas wrote:
> >$post_var = @sessionize_post('post_var');
> >
> >so why exactly is that not an option (or good idea)?
> 
> It IS an option -- and that's what I was doing (except for the 
> suppress error) via this:
> 
> $post_var = sessionize_post('post_var');
> 
> I just wanted to make it simpler and do this:
> 
> $post_var = sessionize_post($post_var);
> 
> But, it turned out to be much more involved. It's just an adventure 
> in key punching.

It takes inefficiency to a whole new level.

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

--- End Message ---
--- Begin Message ---
At 1:39 PM -0800 2/8/08, Jim Lucas wrote:
So, how is this any better then just doing this

$_SESSION = array_merge(array_merge($_SESSION, $_POST), $_GET);

If I replace the two calls to sessionize_*() with the above line, I get the same results. Not sure what I am missing.

First, I didn't say it was better.

Second, you're not missing anything.

Third, if I wanted to merge the arrays, I could use REQUEST and forget the merge.

I was just trying to get the "check the current value of post or get variable and put it into a session" with a single simple statement of:

$whatever = serialize($whatever);

Now, I've have to continue with my original:

$whatever = serialize('whatever');

When dealing with just a few variables, it's not a big deal. But, with the numbers I've been dealing with lately, I was looking to create something simple to cut and paste into.

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
At 4:56 PM -0500 2/8/08, Robert Cummings wrote:
On Fri, 2008-02-08 at 16:51 -0500, tedd wrote:
 At 10:42 PM +0100 2/8/08, Jochem Maas wrote:
 >$post_var = @sessionize_post('post_var');
 >
 >so why exactly is that not an option (or good idea)?

 It IS an option -- and that's what I was doing (except for the
 suppress error) via this:

 $post_var = sessionize_post('post_var');

 I just wanted to make it simpler and do this:

 $post_var = sessionize_post($post_var);

 But, it turned out to be much more involved. It's just an adventure
 in key punching.

It takes inefficiency to a whole new level.

Cheers,
Rob.

Thanks Rob.  :-)

Cheers,

tedd
--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
Hi, thanks for all your help today.

I have the following code and I am trying to order the output. Currently it
seems really random. Can anyone point me in the right direction?

<?php

$dir = "content/current/breaking_news/";

// set pattern
$pattern = ".txt*|.TXT*";

// open directory and parse file list
if (is_dir($dir))
{
if ($dh = opendir($dir))
{

//This is the div that contains the wrap around for the breaking news
section.
echo "
    <div class=\"spstory\" style=\"font-family: Times New Roman, Times,
serif; font-size: 12px; width: 290px;\">
        <div style=\"width: 285px; background-color: #FFFFCC; padding:
3px;\">
            <span class=\"NormalHeadRed\">Breaking News</span>
            <br />Please check here often for breaking news stories.
        </div>
            <p />
        <span class=\"NomalText\">
        
        <ul>";

// iterate over file list
while (($filename = readdir($dh)) !== false)

{

// if filename matches search pattern, print it
if (ereg($pattern, $filename))
   if(strpos($filename,'.')>0)

{
$fh = fopen("$dir" . "$filename", "r");

    $filehead = fgets($fh);

fclose($fh);
echo "
        <li class=\"bn_bullet\">
            <a href=\"/breaking_news/$filename\">$filehead</a>
        </li>";
}
}
echo "
        </ul><p />
        </span>
    </div>";

// close directory
closedir($dh);
}
}

?>

Thank you,

--
Steve Marquez


--- End Message ---
--- Begin Message ---
Pastor Steve wrote:
Hi, thanks for all your help today.

I have the following code and I am trying to order the output. Currently it
seems really random. Can anyone point me in the right direction?

<?php

$dir = "content/current/breaking_news/";

// set pattern
$pattern = ".txt*|.TXT*";

// open directory and parse file list
if (is_dir($dir))
{
if ($dh = opendir($dir))
{

//This is the div that contains the wrap around for the breaking news
section.
echo "
    <div class=\"spstory\" style=\"font-family: Times New Roman, Times,
serif; font-size: 12px; width: 290px;\">
        <div style=\"width: 285px; background-color: #FFFFCC; padding:
3px;\">
            <span class=\"NormalHeadRed\">Breaking News</span>
            <br />Please check here often for breaking news stories.
        </div>
            <p />
        <span class=\"NomalText\">
<ul>";

// iterate over file list
while (($filename = readdir($dh)) !== false)

{

// if filename matches search pattern, print it
if (ereg($pattern, $filename))
   if(strpos($filename,'.')>0)

{
$fh = fopen("$dir" . "$filename", "r");

    $filehead = fgets($fh);

fclose($fh);
echo "
        <li class=\"bn_bullet\">
            <a href=\"/breaking_news/$filename\">$filehead</a>
        </li>";
}
}
echo "
        </ul><p />
        </span>
    </div>";

// close directory
closedir($dh);
}
}

?>

Thank you,

--
Steve Marquez



A cut down version of what you are trying to do, I think.

<?php

$dir = "../../";

// set pattern
$allowed_ftypes = array('php','txt','TXT');

// open directory and parse file list
if (is_dir($dir)) {
    if ( ($files = glob($dir.'*') ) !== false ) {

        // This is the div that contains the wrap around for the breaking news
        // section.
        echo '<div>
            Breaking News<br />
            Please check here often for breaking news stories.
            <p>
            <span class="NomalText">
            <ul>';


        // iterate over file list
        foreach ( $files AS $file ) {

            // if filename matches search pattern, print it
            if ( in_array(array_pop(explode('.', $file) ), $allowed_ftypes ) ) {

                // Open file for reading
                if ( ( $fh = fopen($file, "r") ) !== false ) {

                    // Get the first line of the file
                    $filehead = fgets($fh);

                    // Extract file name for link
                    $filename = array_pop(explode('/', $file));

                    // Display Link
                    echo '<li><a href="/breaking_news/'.$filename.'">'.
                              htmlspecialchars($filehead).'</a></li>';

                    fclose($fh);
                }
            }
        }
        echo '</ul></p></span></div>';
    }
}

?>

--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare

--- End Message ---
--- Begin Message ---
Pastor Steve wrote:
> Hi, thanks for all your help today.
> 
> I have the following code and I am trying to order the output. Currently it
> seems really random. Can anyone point me in the right direction?
> 
> <?php
> 
> $dir = "content/current/breaking_news/";
> 
> // set pattern
> $pattern = ".txt*|.TXT*";
> 
> // open directory and parse file list
> if (is_dir($dir))
> {
> if ($dh = opendir($dir))
> {
> 
> //This is the div that contains the wrap around for the breaking news
> section.
> echo "
>     <div class=\"spstory\" style=\"font-family: Times New Roman, Times,
> serif; font-size: 12px; width: 290px;\">
>         <div style=\"width: 285px; background-color: #FFFFCC; padding:
> 3px;\">
>             <span class=\"NormalHeadRed\">Breaking News</span>
>             <br />Please check here often for breaking news stories.
>         </div>
>             <p />
>         <span class=\"NomalText\">
>         
>         <ul>";
> 
> // iterate over file list
> while (($filename = readdir($dh)) !== false)
> 
> {
> 
> // if filename matches search pattern, print it
> if (ereg($pattern, $filename))
>    if(strpos($filename,'.')>0)
> 
> {
> $fh = fopen("$dir" . "$filename", "r");
> 
>     $filehead = fgets($fh);
> 
> fclose($fh);
> echo "
>         <li class=\"bn_bullet\">
>             <a href=\"/breaking_news/$filename\">$filehead</a>
>         </li>";
> }
> }
> echo "
>         </ul><p />
>         </span>
>     </div>";
> 
> // close directory
> closedir($dh);
> }
> }
> 
> ?>
> 
> Thank you,
> 
> --
> Steve Marquez
> 
> 
How is the output random?  The text from the file, or the order the
files are read?

--- End Message ---
--- Begin Message ---
i hooked up an spl example; and the files are sorted by name.
also, did you want that <p> inside or outside the <span> w/
class=NormalText, because the opening and closing tags are
mixed up..

<?php
class FileIterator extends FilterIterator {
        public function __construct(Iterator $it) {
                if(!($it instanceof DirectoryIterator)) {
                        throw new LogicException(get_class($it) . ' must be
a DirectoryIterator!');
                }
                parent::__construct($it);
        }

        public function accept() {
                if($this->getInnerIterator()->current()->isFile()) {
                        return true;
                }
        }
}

class TextInfoIterator extends ArrayIterator {
        public function __construct($array, $flags=0) {
                $this->ksort();
                parent::__construct($array, $flags);
        }

        public function current() {
                return '<li>' . parent::current() . '</li>';
        }
}

$fileMatchString = '/.*(\.txt|\.TXT)$/';
$resultData = array();

foreach(new RegexIterator(new FileIterator(new
DirectoryIterator('testDir')), $fileMatchString) as $curAllowedFile) {
        try {
                $theFile = $curAllowedFile->openFile('r');
                $theFile->setFlags(SplFileObject::DROP_NEW_LINE);
                $resultData[$curAllowedFile->getFilename()] =
$theFile->fgets();
                unset($theFile);        // close the file ??
        } catch(RuntimeException $e) {
                // do something here
        }
}
?>
<div class="spstory" style="font-family: Times New Roman, Times,serif;
font-size: 12px; width: 290px;">
        <div style="width: 285px; background-color: #FFFFCC; padding:3px;">
                <span class=\"NormalHeadRed\">Breaking News</span>
                <br />Please check here often for breaking news stories.
        </div>
        <p>
                <span class="NomalText">
                        <ul>
                        <?php foreach(new TextInfoIterator($resultData) as
$curTextData) { ?>
                                <?=$curTextData?>
                        <?php } ?>
                        </ul>
                </span>
        </p>
</div>

-nathan

--- End Message ---
--- Begin Message ---
On Fri, Feb 8, 2008 at 9:19 PM, Nathan Nobbe <[EMAIL PROTECTED]> wrote:

> i hooked up an spl example; and the files are sorted by name.
> also, did you want that <p> inside or outside the <span> w/
> class=NormalText, because the opening and closing tags are
> mixed up..
>

damnit; i had a couple of mistakes; so sue me; its friday night!

to ensure the path is in the href; i added it
$resultData[$curAllowedFile->getPathname()] = $theFile->fgets();

to make sure the results are sorted; i sorted them after the parent
ArrayIterator was created
parent::__construct($array, $flags);
$this->ksort();

and lastly, i added the anchor tag
<a href="<?=$curFilename?>"><?=$curTextData?></a>

i could use a drink right about now..=/

-nathan

--- End Message ---
--- Begin Message ---
On Fri, 2008-02-08 at 21:19 -0500, Nathan Nobbe wrote:
> i hooked up an spl example; and the files are sorted by name.
> also, did you want that <p> inside or outside the <span> w/
> class=NormalText, because the opening and closing tags are
> mixed up..
> 

Here is another, generic extension filter with SPL. Untested, and I have
just woken up, so if it doesn't work... :-P

class ExtensionFilter extends FilterIterator {

  private $ext; 
  private $it;

  public function __construct(DirectoryIterator $it, $ext) {
      parent::__construct($it);
      $this->it = $it;
      $this->ext = $ext;
  }
  public function accept() {
      if ( ! $this->it->isDir() ) {
        $ext = array_pop(explode('.', $this->current()));
        return $ext != $this->ext;
      }
      return true;
  }
}

--Paul
-- 
------------------------------------------------------------.
| Chisimba PHP5 Framework - http://avoir.uwc.ac.za           |
:------------------------------------------------------------:

All Email originating from UWC is covered by disclaimer 
http://www.uwc.ac.za/portal/public/portal_services/disclaimer.htm 

--- End Message ---
--- Begin Message ---
On Saturday 09 February 2008 02:22:28 Shawn McKenzie wrote:
> Pastor Steve wrote:
> > Hi, thanks for all your help today.
> >
> > I have the following code and I am trying to order the output. Currently
> > it seems really random. Can anyone point me in the right direction?
> >
> > <?php
> >
> > $dir = "content/current/breaking_news/";
> >
> > // set pattern
> > $pattern = ".txt*|.TXT*";
> >
> > // open directory and parse file list
> > if (is_dir($dir))
> > {
> > if ($dh = opendir($dir))
> > {
> >
> > //This is the div that contains the wrap around for the breaking news
> > section.
> > echo "
> >     <div class=\"spstory\" style=\"font-family: Times New Roman, Times,
> > serif; font-size: 12px; width: 290px;\">
> >         <div style=\"width: 285px; background-color: #FFFFCC; padding:
> > 3px;\">
> >             <span class=\"NormalHeadRed\">Breaking News</span>
> >             <br />Please check here often for breaking news stories.
> >         </div>
> >             <p />
> >         <span class=\"NomalText\">
> >
> >         <ul>";
> >
> > // iterate over file list
> > while (($filename = readdir($dh)) !== false)
> >
> > {
> >
> > // if filename matches search pattern, print it
> > if (ereg($pattern, $filename))
> >    if(strpos($filename,'.')>0)
> >
> > {
> > $fh = fopen("$dir" . "$filename", "r");
> >
> >     $filehead = fgets($fh);
> >
> > fclose($fh);
> > echo "
> >         <li class=\"bn_bullet\">
> >             <a href=\"/breaking_news/$filename\">$filehead</a>
> >         </li>";
> > }
> > }
> > echo "
> >         </ul><p />
> >         </span>
> >     </div>";
> >
> > // close directory
> > closedir($dh);
> > }
> > }
> >
> > ?>
> >
> > Thank you,
> >
> > --
> > Steve Marquez
>
> How is the output random?  The text from the file, or the order the
> files are read?

I recon its the same problem I faced where files are read in the fifo order 
instead of alphabetical. or did I miss out on this thread completly?




-- 
---
Børge Holen
http://www.arivene.net

--- End Message ---
--- Begin Message ---
        Posting Summary for PHP-General List
        Week Ending: Friday, 8 February, 2008

        Messages            | Bytes              | Sender
        --------------------+--------------------+------------------
        391 (100%)          581347 (100%)       EVERYONE
        32     (8.2%)      41862   (7.2%)      Daniel Brown <parasane at gmail 
dot com>
        27     (6.9%)      29259   (5%)        Nathan Nobbe <quickshiftin at 
gmail dot com>
        21     (5.4%)      23274   (4%)        Paul Scott <pscott at uwc dot ac 
dot za>
        17     (4.3%)      26180   (4.5%)      Jochem Maas <jochem at iamjochem 
dot com>
        15     (3.8%)      23318   (4%)        Richard Lynch <ceo at l-i-e dot 
com>
        15     (3.8%)      9331    (1.6%)      Per Jessen <per at computer dot 
org>
        14     (3.6%)      15963   (2.7%)      Eric Butera <eric dot butera at 
gmail dot com>
        14     (3.6%)      11187   (1.9%)      Richard Heyes <richardh at 
phpguru dot org>
        12     (3.1%)      52246   (9%)        szalinski <barneytramble at 
gmail dot com>
        11     (2.8%)      27715   (4.8%)      Shawn McKenzie <nospam at 
mckenzies dot net>
        11     (2.8%)      9530    (1.6%)      Greg Donald <gdonald at gmail 
dot com>
        9      (2.3%)      14608   (2.5%)      Jim Lucas <lists at cmsws dot 
com>
        9      (2.3%)      15210   (2.6%)      Casey <heavyccasey at gmail dot 
com>
        8      (2%)        12953   (2.2%)      Andrew Ballard <aballard at 
gmail dot com>
        7      (1.8%)      11631   (2%)        Robert Cummings <robert at 
interjinn dot com>
        7      (1.8%)      21742   (3.7%)      Manuel Lemos <mlemos at acm dot 
org>
        6      (1.5%)      14733   (2.5%)      Mad Unix <madunix at gmail dot 
com>
        6      (1.5%)      10924   (1.9%)      Zoltán Németh <znemeth at 
alterationx dot hu>
        6      (1.5%)      11225   (1.9%)      Wolf <LoneWolf at nc dot rr dot 
com>
        6      (1.5%)      8139    (1.4%)      Jason Pruim <japruim at raoset 
dot com>
        6      (1.5%)      4308    (0.7%)      js <ebgssth at gmail dot com>
        5      (1.3%)      14543   (2.5%)      Robbert van Andel <robbert at 
vafam dot com>
        5      (1.3%)      5272    (0.9%)      Chris <dmagick at gmail dot com>
        5      (1.3%)      4450    (0.8%)      Martin Marques <martin at 
marquesminen dot com dot ar>
        4      (1%)        4817    (0.8%)      Prabath Kumarasinghe <prabath321 
at yahoo dot com>
        4      (1%)        11452   (2%)        Nathan Rixham <nrixham at gmail 
dot com>
        4      (1%)        7322    (1.3%)      Warren Vail <warren at vailtech 
dot net>
        4      (1%)        4249    (0.7%)      Bastien Koert <bastien_k at 
hotmail dot com>
        3      (0.8%)      2577    (0.4%)      clive <clive_lists at 
immigrationunit dot com>
        3      (0.8%)      3088    (0.5%)      jeffry s <paragasu at gmail dot 
com>
        3      (0.8%)      4269    (0.7%)      Larry Garfield <larry at 
garfieldtech dot com>
        3      (0.8%)      2680    (0.5%)      Pieter du Toit <pieter at 
lpwebdesign dot co dot za>
        3      (0.8%)      3762    (0.6%)      John Taylor-Johnston <John dot 
Taylor-Johnston at cegepsherbrooke dot qc dot ca>
        3      (0.8%)      9312    (1.6%)      Louie Miranda <lmiranda at gmail 
dot com>
        3      (0.8%)      14240   (2.4%)      McNaught, Scott <scott dot 
mcnaught at synergy8 dot com>
        3      (0.8%)      1511    (0.3%)      Ron Piggott <ron dot php at 
actsministries dot org>
        2      (0.5%)      1786    (0.3%)      John Taylor-Johnston <jt dot 
johnston at USherbrooke dot ca>
        2      (0.5%)      839     (0.1%)      AmirBehzad Eslami <behzad dot 
eslami at gmail dot com>
        2      (0.5%)      1561    (0.3%)      blackwater dev <blackwaterdev at 
gmail dot com>
        2      (0.5%)      841     (0.1%)      nihilism machine 
<nihilismmachine at gmail dot com>
        2      (0.5%)      2058    (0.4%)      Michael Moyle <mmoyle at gaba 
dot co dot jp>
        2      (0.5%)      1147    (0.2%)      ehl lhe <ehl22_12 at hotmail dot 
com>
        2      (0.5%)      13541   (2.3%)      Andrés Robinet <agrobinet at 
bestplace dot biz>
        2      (0.5%)      2559    (0.4%)      Nikolay Ananiev <ananiev at 
thegdb dot com>
        2      (0.5%)      2226    (0.4%)      VamVan <vamseevan at gmail dot 
com>
        2      (0.5%)      1784    (0.3%)      Alain Roger <raf dot news at 
gmail dot com>
        2      (0.5%)      3927    (0.7%)      Mr Webber <captain_webber at 
hotmail dot com>
        2      (0.5%)      2935    (0.5%)      David Giragosian <dgiragosian at 
gmail dot com>
        2      (0.5%)      1548    (0.3%)      pobox at verysmall dot org 
<pobox at verysmall dot org>
        2      (0.5%)      1661    (0.3%)      Feris Thia C dot  <feris dot 
thia at gmail dot com>
        2      (0.5%)      1244    (0.2%)      LKSunny <ad at pc86 dot com>
        2      (0.5%)      1662    (0.3%)      Robert Fitzpatrick <lists at 
webtent dot net>
        1      (0.3%)      365     (0.1%)      Brian Dunning <brian at 
briandunning dot com>
        1      (0.3%)      991     (0.2%)      Richard <php_list at ghz dot fr>
        1      (0.3%)      2940    (0.5%)      Fnutt <trond at fnutt dot org>
        1      (0.3%)      383     (0.1%)      Bruce Cowin <bdc at topenergy 
dot co dot nz>
        1      (0.3%)      1327    (0.2%)      Rob Gould <gouldimg at mac dot 
com>
        1      (0.3%)      1041    (0.2%)      zerof <zerof at terra dot com 
dot br>
        1      (0.3%)      860     (0.1%)      Fahad javed <fahadedupk at gmail 
dot com>
        1      (0.3%)      586     (0.1%)      David Robley <robleyd at aapt 
dot net dot au>
        1      (0.3%)      845     (0.1%)      Leonard Burton <leonardburton at 
gmail dot com>
        1      (0.3%)      1258    (0.2%)      Legolas wood <legolas dot w at 
gmail dot com>
        1      (0.3%)      866     (0.1%)      Dare Williams <darrenwilly at 
yahoo dot com>
        1      (0.3%)      1043    (0.2%)      Louie Henry <louiehenry at 
brktel dot on dot ca>
        1      (0.3%)      1623    (0.3%)      Colin Guthrie <gmane at colin 
dot guthr dot ie>
        1      (0.3%)      437     (0.1%)      Steve Marquez <smarquez at 
marquez-design dot com>
        1      (0.3%)      1124    (0.2%)      Rob G <robg at areyouserved dot 
com>
        1      (0.3%)      1019    (0.2%)      puneetjain <puneet dot jain1 at 
wipro dot com>
        1      (0.3%)      269     (0%)        MaryAnn Woodall <mawoodall at 
earthlink dot net>
        1      (0.3%)      1280    (0.2%)      Floor Terra <floort at gmail dot 
com>
        1      (0.3%)      1218    (0.2%)      C dot R dot Vegelin <cr dot 
vegelin at hetnet dot nl>
        1      (0.3%)      802     (0.1%)      mike <mike503 at gmail dot com>
        1      (0.3%)      698     (0.1%)      Michael Fischer <michi dot 
fischer at gmx dot net>
        1      (0.3%)      2838    (0.5%)      bruce <bedouglas at earthlink 
dot net>
        1      (0.3%)      1115    (0.2%)      chetan rane <chetan dot d dot 
rane at gmail dot com>
        1      (0.3%)      721     (0.1%)      Siegfried Gipp <siegfried at 
rorkvell dot de>
        1      (0.3%)      265     (0%)        doc <dingus_76 at hotmail dot 
com>
        1      (0.3%)      742     (0.1%)      j dot vanhooren at e2ma dot nl
        1      (0.3%)      368     (0.1%)      Jonesy <gmane at jonz dot net>
        1      (0.3%)      496     (0.1%)      dg <daneane at bluerodeo dot com>
        1      (0.3%)      266     (0%)        RandMan <ad at pc86 dot com>
        1      (0.3%)      556     (0.1%)      Daevid Vincent <daevid at daevid 
dot com>
        1      (0.3%)      136     (0%)        <salon at andersonsturgess dot 
com>
        1      (0.3%)      1237    (0.2%)      tedd <tedd dot sperling at gmail 
dot com>
        1      (0.3%)      3357    (0.6%)      venkatk at aol dot in
        1      (0.3%)      1482    (0.3%)      Michelle Konzack <linux4michelle 
at freenet dot de>
        1      (0.3%)      1114    (0.2%)      Edward Kay <edward at labhut dot 
com>
        1      (0.3%)      567     (0.1%)      Aschwin Wesselius <get at 
illuminated dot nl>
        1      (0.3%)      506     (0.1%)      Zoran Bogdanov <test1 dot test1 
at hi dot t-com dot hr>
        1      (0.3%)      1215    (0.2%)      Ford, Mike <M dot Ford at 
leedsmet dot ac dot uk>
        1      (0.3%)      2707    (0.5%)      Richard <richi_8 at hotmail dot 
com>
        1      (0.3%)      1424    (0.2%)      Peter Ford <pete at justcroft 
dot com>
        1      (0.3%)      237     (0%)        Cameron Just <c dot just at 
phoenixdigital dot com>
        1      (0.3%)      352     (0.1%)      Hiep Nguyen <hiep at ee dot ucr 
dot edu>
        1      (0.3%)      401     (0.1%)      George Pitcher <george dot 
pitcher at ingenta dot com>
        1      (0.3%)      1244    (0.2%)      Adam Williams <awilliam at mdah 
dot state dot ms dot us>
        1      (0.3%)      6825    (1.2%)      PostTrack [Dan Brown] 
<listwatch-php-general at pilotpig dot net>


NOTE: Numbers may not add up to 100% due to protection of names and addresses 
upon request.

DISCLAIMER: If you want your email address omitted from future weekly reports,
please email me privately at [EMAIL PROTECTED] and it will be removed.

--- End Message ---

Reply via email to