php-general Digest 5 Sep 2009 08:12:10 -0000 Issue 6323

Topics (messages 297690 through 297723):

Re: Searching on AlphaNumeric Content Only
        297690 by: Eddie Drapkin
        297692 by: Robert Cummings
        297711 by: Tommy Pham
        297712 by: Paul M Foster
        297719 by: Robert Cummings
        297721 by: Paul M Foster
        297722 by: Tommy Pham

script failing at same line
        297691 by: jim white
        297695 by: Jay Blanchard
        297696 by: jim white
        297697 by: Ben Dunlap
        297699 by: jim white
        297714 by: Ben Dunlap
        297718 by: jim white

Re: Converting URL's to hyperlinks.
        297693 by: Daevid Vincent
        297694 by: Tom Chubb

Re: Include Files in HTML
        297698 by: Joost
        297706 by: sono-io.fannullone.us
        297715 by: Tommy Pham
        297716 by: Tommy Pham
        297717 by: phphelp -- kbk

accessing variable from inside a class
        297700 by: Lars Nielsen
        297702 by: James Colannino
        297708 by: Shawn McKenzie
        297709 by: Shawn McKenzie
        297710 by: Lars Nielsen

PHP6 Stable Release Schedule
        297701 by: Bobby Pejman
        297703 by: Daniel Brown
        297723 by: Richard Heyes

Re: how to strip empty lines out of a txt using  preg_replace()
        297704 by: Jim Lucas
        297720 by: Clancy

Re: PHP inserting carriage returns into POST values?
        297705 by: Nisse Engström
        297707 by: Paul M Foster
        297713 by: James Colannino

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
On Fri, Sep 4, 2009 at 12:02 PM, Lupus
Michaelis<mickael+...@lupusmic.org> wrote:
> Ashley Sheridan a écrit :
>
>> You'll have far greater performance issues if you retrieve all those
>> records and attempt to do the same thing inside of PHP...
>
>  It's why I speak about « avoiding » and not « bannishing ». Like can be
> usefull, I used to use it. But it is not the a good answer to all problems.
> The problem with like operator is it can't use the index (or in a very
> limited way). So I try to warn about it.
>
>  So said, I never submit an all-retrieving method. I know it isn't the
> solution too.
>
> --
> Mickaël Wolff aka Lupus Michaelis
> http://lupusmic.org
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

So far, in this thread, there've been a few solutions:
1) LIKE in SQL.
2) REGEXP in SQL.
3) PCRE in PHP
4) Other fetch all methods in PHP.

The one thing that I'm seeing as a consistent agreement is that the
performance hit of whichever of the aforementioned measures is going
to be enough to be considering something else.   I briefly mentioned -
I apologize for the brevity of that email because I was in a hurry -
that a legitimate full text search engine is the right solution to
this problem.  The only problem with deploying a full text search
engine is going to be the difficulty in the deployment and perhaps
issues if you're on shared hosting (but then again I am of the opinion
that those who choose to run with shared hosting dig their own graves
in more ways than one).

What a full text search engine gives you is flexibility in your
searches, such that the initial question, when I read it, I thought
"Oh, someone will tell him to use Sphinx or Solr as both have special
filters for word seperation and would handle this without any special
instruction."  Instead, this is never even brought up!

Why was using a full text search engine to do this sort of thing - not
to mention the other benefits that it would bring (responsiveness and
flexibility in searching, speed, decreased use of MySQL, etc. etc.) -
rejected so offhandedly?  I can't actually think of a better way to do
this without requiring a whole heap of overhead, either processing or
programming.

--- End Message ---
--- Begin Message ---
Eddie Drapkin wrote:
On Fri, Sep 4, 2009 at 12:02 PM, Lupus
Michaelis<mickael+...@lupusmic.org> wrote:
Ashley Sheridan a écrit :

You'll have far greater performance issues if you retrieve all those
records and attempt to do the same thing inside of PHP...
 It's why I speak about « avoiding » and not « bannishing ». Like can be
usefull, I used to use it. But it is not the a good answer to all problems.
The problem with like operator is it can't use the index (or in a very
limited way). So I try to warn about it.

 So said, I never submit an all-retrieving method. I know it isn't the
solution too.

--
Mickaël Wolff aka Lupus Michaelis
http://lupusmic.org

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



So far, in this thread, there've been a few solutions:
1) LIKE in SQL.
2) REGEXP in SQL.
3) PCRE in PHP
4) Other fetch all methods in PHP.

The one thing that I'm seeing as a consistent agreement is that the
performance hit of whichever of the aforementioned measures is going
to be enough to be considering something else.   I briefly mentioned -
I apologize for the brevity of that email because I was in a hurry -
that a legitimate full text search engine is the right solution to
this problem.  The only problem with deploying a full text search
engine is going to be the difficulty in the deployment and perhaps
issues if you're on shared hosting (but then again I am of the opinion
that those who choose to run with shared hosting dig their own graves
in more ways than one).

What a full text search engine gives you is flexibility in your
searches, such that the initial question, when I read it, I thought
"Oh, someone will tell him to use Sphinx or Solr as both have special
filters for word seperation and would handle this without any special
instruction."  Instead, this is never even brought up!

Why was using a full text search engine to do this sort of thing - not
to mention the other benefits that it would bring (responsiveness and
flexibility in searching, speed, decreased use of MySQL, etc. etc.) -
rejected so offhandedly?  I can't actually think of a better way to do
this without requiring a whole heap of overhead, either processing or
programming.

I've just sort of stopped in on this thread... but why isn't MySQL's FULLTEXT engine being considered?

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--- End Message ---
--- Begin Message ---
----- Original Message ----
> From: Robert Cummings <rob...@interjinn.com>
> To: Eddie Drapkin <oorza...@gmail.com>
> Cc: Lupus Michaelis <mickael+...@lupusmic.org>; php-gene...@lists.php.net
> Sent: Friday, September 4, 2009 1:36:08 PM
> Subject: Re: [PHP] Searching on AlphaNumeric Content Only
> 
> Eddie Drapkin wrote:
> > On Fri, Sep 4, 2009 at 12:02 PM, Lupus
> > Michaeliswrote:
> >> Ashley Sheridan a écrit :
> >>
> >>> You'll have far greater performance issues if you retrieve all those
> >>> records and attempt to do the same thing inside of PHP...
> >>  It's why I speak about « avoiding » and not « bannishing ». Like can be
> >> usefull, I used to use it. But it is not the a good answer to all problems.
> >> The problem with like operator is it can't use the index (or in a very
> >> limited way). So I try to warn about it.
> >>
> >>  So said, I never submit an all-retrieving method. I know it isn't the
> >> solution too.
> >>
> >> --
> >> Mickaël Wolff aka Lupus Michaelis
> >> http://lupusmic.org
> >>
> >> --
> >> PHP General Mailing List (http://www.php.net/)
> >> To unsubscribe, visit: http://www.php.net/unsub.php
> >>
> >>
> > 
> > So far, in this thread, there've been a few solutions:
> > 1) LIKE in SQL.
> > 2) REGEXP in SQL.
> > 3) PCRE in PHP
> > 4) Other fetch all methods in PHP.
> > 
> > The one thing that I'm seeing as a consistent agreement is that the
> > performance hit of whichever of the aforementioned measures is going
> > to be enough to be considering something else.   I briefly mentioned -
> > I apologize for the brevity of that email because I was in a hurry -
> > that a legitimate full text search engine is the right solution to
> > this problem.  The only problem with deploying a full text search
> > engine is going to be the difficulty in the deployment and perhaps
> > issues if you're on shared hosting (but then again I am of the opinion
> > that those who choose to run with shared hosting dig their own graves
> > in more ways than one).
> > 
> > What a full text search engine gives you is flexibility in your
> > searches, such that the initial question, when I read it, I thought
> > "Oh, someone will tell him to use Sphinx or Solr as both have special
> > filters for word seperation and would handle this without any special
> > instruction."  Instead, this is never even brought up!
> > 
> > Why was using a full text search engine to do this sort of thing - not
> > to mention the other benefits that it would bring (responsiveness and
> > flexibility in searching, speed, decreased use of MySQL, etc. etc.) -
> > rejected so offhandedly?  I can't actually think of a better way to do
> > this without requiring a whole heap of overhead, either processing or
> > programming.
> 
> I've just sort of stopped in on this thread... but why isn't MySQL's 
> FULLTEXT engine being considered?

If I remember correctly, it's only on available on MyISAM table type.  I don't
think the OP mentioned that he's using MyISAM or MySQL for that matter.

> 
> Cheers,
> Rob.
> -- 
> http://www.interjinn.com
> Application and Templating Framework for PHP
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php


--- End Message ---
--- Begin Message ---
On Fri, Sep 04, 2009 at 04:22:18PM -0400, Eddie Drapkin wrote:

> On Fri, Sep 4, 2009 at 12:02 PM, Lupus
> Michaelis<mickael+...@lupusmic.org> wrote:

> if you're on shared hosting (but then again I am of the opinion
> that those who choose to run with shared hosting dig their own graves
> in more ways than one).

Any time you or someone else would like to backstop me in setting up a
dedicated server on rackspace or somewhere else, for free or really
cheap, you let me know! Otherwise, those of us with less than complete
expertise in server setup are stuck with shared hosting. ;-}

Paul

-- 
Paul M. Foster

--- End Message ---
--- Begin Message ---
Paul M Foster wrote:
On Fri, Sep 04, 2009 at 04:22:18PM -0400, Eddie Drapkin wrote:

On Fri, Sep 4, 2009 at 12:02 PM, Lupus
Michaelis<mickael+...@lupusmic.org> wrote:

if you're on shared hosting (but then again I am of the opinion
that those who choose to run with shared hosting dig their own graves
in more ways than one).

Any time you or someone else would like to backstop me in setting up a
dedicated server on rackspace or somewhere else, for free or really
cheap, you let me know! Otherwise, those of us with less than complete
expertise in server setup are stuck with shared hosting. ;-}

For a few hundred bucks a year you can get a VPS (Virtual Private Server), which gives you root access. once you get a couple of clients on it, it will pay for itself year after year. If you have clients that don't use much resources, you can put a few on and even make a profit on the hosting alone.

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--- End Message ---
--- Begin Message ---
On Fri, Sep 04, 2009 at 08:15:41PM -0400, Robert Cummings wrote:

> Paul M Foster wrote:
>> On Fri, Sep 04, 2009 at 04:22:18PM -0400, Eddie Drapkin wrote:
>>
>>> On Fri, Sep 4, 2009 at 12:02 PM, Lupus
>>> Michaelis<mickael+...@lupusmic.org> wrote:
>>
>>> if you're on shared hosting (but then again I am of the opinion
>>> that those who choose to run with shared hosting dig their own graves
>>> in more ways than one).
>>
>> Any time you or someone else would like to backstop me in setting up a
>> dedicated server on rackspace or somewhere else, for free or really
>> cheap, you let me know! Otherwise, those of us with less than complete
>> expertise in server setup are stuck with shared hosting. ;-}
>
> For a few hundred bucks a year you can get a VPS (Virtual Private
> Server), which gives you root access. once you get a couple of clients
> on it, it will pay for itself year after year. If you have clients that
> don't use much resources, you can put a few on and even make a profit on
> the hosting alone.

Oh sure. Well aware of it. The problem is not finding a VPS or working
with root access or anything like that. The problem is expertise. POP3,
SMTP, SSH, HTTP, DNS, firewall security while still allowing access to
outward facing servers, etc. It's more expertise than most people have,
including me. The servers I run are internal and don't have to deal with
the rigors of the internet, and only serve a couple of people. Setting
up multiple domains under an Apache server is black magic to me, for
instance. And then there's backups, and
what-do-I-do-if-the-server-fails, etc. Sheesh.

Paul

-- 
Paul M. Foster

--- End Message ---
--- Begin Message ---
----- Original Message ----
> From: Paul M Foster <pa...@quillandmouse.com>
> To: php-gene...@lists.php.net
> Sent: Friday, September 4, 2009 9:15:08 PM
> Subject: Re: [PHP] Searching on AlphaNumeric Content Only
> 
> On Fri, Sep 04, 2009 at 08:15:41PM -0400, Robert Cummings wrote:
> 
> > Paul M Foster wrote:
> >> On Fri, Sep 04, 2009 at 04:22:18PM -0400, Eddie Drapkin wrote:
> >>
> >>> On Fri, Sep 4, 2009 at 12:02 PM, Lupus
> >>> Michaeliswrote:
> >>
> >>> if you're on shared hosting (but then again I am of the opinion
> >>> that those who choose to run with shared hosting dig their own graves
> >>> in more ways than one).
> >>
> >> Any time you or someone else would like to backstop me in setting up a
> >> dedicated server on rackspace or somewhere else, for free or really
> >> cheap, you let me know! Otherwise, those of us with less than complete
> >> expertise in server setup are stuck with shared hosting. ;-}
> >
> > For a few hundred bucks a year you can get a VPS (Virtual Private
> > Server), which gives you root access. once you get a couple of clients
> > on it, it will pay for itself year after year. If you have clients that
> > don't use much resources, you can put a few on and even make a profit on
> > the hosting alone.
> 
> Oh sure. Well aware of it. The problem is not finding a VPS or working
> with root access or anything like that. The problem is expertise. POP3,
> SMTP, SSH, HTTP, DNS, firewall security while still allowing access to
> outward facing servers, etc. It's more expertise than most people have,
> including me. The servers I run are internal and don't have to deal with
> the rigors of the internet, and only serve a couple of people. Setting
> up multiple domains under an Apache server is black magic to me, for
> instance. And then there's backups, and
> what-do-I-do-if-the-server-fails, etc. Sheesh.

I stand corrected.  You paid for peace of mind :D


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


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

I have a script that intermittently fails at the same line. I am trying to write some code that will throw an exception after 5 seconds if the command on that line fails and the script freezes.
Any ideas?

Jim White


--- End Message ---
--- Begin Message ---
[snip]
I have a script that intermittently fails at the same line. I am trying 
to write some code that will throw an exception after 5 seconds if the 
command on that line fails and the script freezes.
Any ideas?
[/snip]

I have lots of ideas! But those really won't help you :)

We need to see the code at that line and be told what is being done in
order to make a reasonable guess.

My bet is that the data being fed to the script has a character that is
not expected or something.

--- End Message ---
--- Begin Message ---
$map = ms_newMapObj($mapfile);

The command creates a new mapscript object.

Jay Blanchard wrote:
[snip]
I have a script that intermittently fails at the same line. I am trying to write some code that will throw an exception after 5 seconds if the command on that line fails and the script freezes.
Any ideas?
[/snip]

I have lots of ideas! But those really won't help you :)

We need to see the code at that line and be told what is being done in
order to make a reasonable guess.

My bet is that the data being fed to the script has a character that is
not expected or something.



--- End Message ---
--- Begin Message ---
> $map = ms_newMapObj($mapfile);
>
> The command creates a new mapscript object.
>
>
And PHP is hanging somewhere inside that constructor? Is this in a web
context or a command-line context? Or both?

--- End Message ---
--- Begin Message --- It's a web app that draws maps in a browser. Sometime it will generate a seg fault. The command should not take long, so if there is some script construct that will throw an exception after a few seconds if the command has not completed I could signal the user that the map will not draw and to reload the page.

Jim

Ben Dunlap wrote:

    $map = ms_newMapObj($mapfile);

    The command creates a new mapscript object.


And PHP is hanging somewhere inside that constructor? Is this in a web context or a command-line context? Or both?


--- End Message ---
--- Begin Message ---
On Fri, Sep 4, 2009 at 2:38 PM, jim white <jbw2...@earthlink.net> wrote:

> It's a web app that draws maps in a browser. Sometime it will generate a
> seg fault. The command should not take long, so if there is some script
> construct that will throw an exception after a few seconds if the command
> has not completed I could signal the user that the map will not draw and to
> reload the page.


There's a pecl extension called Libevent that can apparently trigger an
action to occur after a certain amount of time has elapsed:

http://us3.php.net/manual/en/ref.libevent.php

I've not used it and have no idea how mature or reliable it is. I'm also
wondering whether any solution will work that relies on the same script
that's about to trigger a segfault.

I think I'd be inclined to build an XHR-based monitor to run in the user's
browser. Even simpler would be to start the map-building process
asynchronously with XHR and then just alert the user, or automatically
refresh the browser, if a certain amount of time elapses before you get a
response from the map-building script. But I don't know how much you'd have
to alter your existing client-side code to use the latter method.

Either way it's creeping away from PHP so maybe I should leave it at that.

Ben

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

Thanks I'll look at libevent. I have also been thinking about using an XHR approach, but wonder how passing PHP references works with javascript.

Jim

Ben Dunlap wrote:
On Fri, Sep 4, 2009 at 2:38 PM, jim white <jbw2...@earthlink.net <mailto:jbw2...@earthlink.net>> wrote:

    It's a web app that draws maps in a browser. Sometime it will
    generate a seg fault. The command should not take long, so if
    there is some script construct that will throw an exception after
    a few seconds if the command has not completed I could signal the
    user that the map will not draw and to reload the page.


There's a pecl extension called Libevent that can apparently trigger an action to occur after a certain amount of time has elapsed:

http://us3.php.net/manual/en/ref.libevent.php

I've not used it and have no idea how mature or reliable it is. I'm also wondering whether any solution will work that relies on the same script that's about to trigger a segfault.

I think I'd be inclined to build an XHR-based monitor to run in the user's browser. Even simpler would be to start the map-building process asynchronously with XHR and then just alert the user, or automatically refresh the browser, if a certain amount of time elapses before you get a response from the map-building script. But I don't know how much you'd have to alter your existing client-side code to use the latter method.

Either way it's creeping away from PHP so maybe I should leave it at that.

Ben



--- End Message ---
--- Begin Message ---
 

> -----Original Message-----
> From: Lupus Michaelis [mailto:mickael+...@lupusmic.org] 
> Sent: Friday, September 04, 2009 7:46 AM
> To: php-gene...@lists.php.net
> Subject: Re: [PHP] Converting URL's to hyperlinks.
> 
> Daevid Vincent a écrit :
> > Maybe I misunderstood the OP,
>    OP ?

Original Poster

> > but wouldn't this (or something like it) be

Note the "something like it". I didn't write his app, just provided a
starting point.

> > $url = preg_replace("/(\...@\w+\.[a-za-z]{2,3})/i", "<a
> > href='mailto:$1'>$1</a>", $url);
>    This violate the numerous RFC about mail addresses, and some other 
> stuffs.

Blah blah blah.
I've used this code for about 6 years now and have yet to find emails that
it didn't work for. If someone has some funky (whacky) RFC extremity, then
so be it. That's their problem. Most people have NORMAL emails that follow
the above.

But you are correct, I have revised it to be a little more forgiving of some
allowed characters...

preg_replace("/([\w\.\-...@[\w\.\-_]+\.\w{2,6})/i",

> > 
> > $url = 
> preg_replace("/\s(http:\/\/)?(\w*\.?\w*\.[a-zA-Z]{2,3}.*?\s)/i", " <a
> > href='http://$2' target='_blank'>$2</a>", $url);
> 
>    Same as previously. What about .info, .museum and so on tld ? 

What about them? It's going to depend on how/where you use this. In my case,
2 and 3 letter domains are all I encounter. It's trivial to make it {2,6} if
you really are going to encounter a .museum domain. DOUBTFUL, but sure, I'll
concede the three extra letters. ;-)

However, you point out a few edge cases and so I optimized mine and now use
this one:
http://snipplr.com/view/2371/regex-regular-expression-to-match-a-url/

> > Oh, and your regex isn't 
> smart (you use the case insensitivity flag, but seek A-Z 
> characters...) :D

Noted. Thanks for the optimization.


--- End Message ---
--- Begin Message ---
2009/9/4 Daevid Vincent <dae...@daevid.com>

>
>
> > -----Original Message-----
> > From: Lupus Michaelis 
> > [mailto:mickael+...@lupusmic.org<mickael%2b...@lupusmic.org>
> ]
> > Sent: Friday, September 04, 2009 7:46 AM
> > To: php-gene...@lists.php.net
> > Subject: Re: [PHP] Converting URL's to hyperlinks.
> >
> > Daevid Vincent a écrit :
> > > Maybe I misunderstood the OP,
> >    OP ?
>
> Original Poster
>
> > > but wouldn't this (or something like it) be
>
> Note the "something like it". I didn't write his app, just provided a
> starting point.
>
> > > $url = preg_replace("/(\...@\w+\.[a-za-z]{2,3})/i", "<a
> > > href='mailto:$1'>$1</a>", $url);
> >    This violate the numerous RFC about mail addresses, and some other
> > stuffs.
>
> Blah blah blah.
> I've used this code for about 6 years now and have yet to find emails that
> it didn't work for. If someone has some funky (whacky) RFC extremity, then
> so be it. That's their problem. Most people have NORMAL emails that follow
> the above.
>
> But you are correct, I have revised it to be a little more forgiving of
> some
> allowed characters...
>
> preg_replace("/([\w\.\-...@[\w\.\-_]+\.\w{2,6})/i",
>
> > >
> > > $url =
> > preg_replace("/\s(http:\/\/)?(\w*\.?\w*\.[a-zA-Z]{2,3}.*?\s)/i", " <a
> > > href='http://$2' target='_blank'>$2</a>", $url);
> >
> >    Same as previously. What about .info, .museum and so on tld ?
>
> What about them? It's going to depend on how/where you use this. In my
> case,
> 2 and 3 letter domains are all I encounter. It's trivial to make it {2,6}
> if
> you really are going to encounter a .museum domain. DOUBTFUL, but sure,
> I'll
> concede the three extra letters. ;-)
>
> However, you point out a few edge cases and so I optimized mine and now use
> this one:
> http://snipplr.com/view/2371/regex-regular-expression-to-match-a-url/
>
> > > Oh, and your regex isn't
> > smart (you use the case insensitivity flag, but seek A-Z
> > characters...) :D
>
> Noted. Thanks for the optimization.
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Thanks for posting that! Will be really handy for me!

--- End Message ---
--- Begin Message ---
"Bob McConnell" wrote:

> From: sono-io at fannullone.us
> 
>> In my readings, I've run across examples showing include files
> being
>> called from within the <head></head> tags, and other examples showing
> 
>> them called within <body></body>.  I've always put them in the header
> 
>> section myself, but I was wondering if one is better than the other,
>> or is it just personal preference?
> 
> Depends on what you are including. The only tags that can be inside the
> head are <base>, <link>, <meta>, <script>, <style>,  and <title>.
> Everything else is either body or prologue.
> 
> The full specs can be found at
> <http://www.w3schools.com/tags/default.asp>.
> 
> Bob McConnell

Sure enough. What the OP might not have realized:

In the end, what PHP evaluates to, is a stream of html, script, css etc 
text/data, which is sent to the browser. PHP's include( <file> ) statement 
inserts the content of <file> here-and-now. You can even put the include 
statement within a for loop in order to include something multiple times... 
In that sense it is more like a /function/ and really different from cpp's 
#include /directive/.

<file> can contain PHP code, which is evaluated as if it was here-and-now in 
the including PHP file; it can contain text/data, which is appended to the 
text/data stream being produced.

All in all, to PHP the spot of file inclusion is not interesting, as long as 
the resulting PHP code and/or stream data is meaningful.

Now back to you, Bob :-)

Regards,
Joost.

--- End Message ---
--- Begin Message ---

On Sep 4, 2009, at 1:05 PM, Bob McConnell wrote:

Depends on what you are including. The only tags that can be inside the
head are <base>, <link>, <meta>, <script>, <style>,  and <title>.
Everything else is either body or prologue.

        I meant PHP includes like this one:
<?php @include_once("/home/passwords/login.php"); ?>

Frank

--- End Message ---
--- Begin Message ---
----- Original Message ----
> From: "sono...@fannullone.us" <sono...@fannullone.us>
> To: PHP General List <php-gene...@lists.php.net>
> Sent: Friday, September 4, 2009 12:57:08 PM
> Subject: [PHP] Include Files in HTML
> 
>     In my readings, I've run across examples showing include files being 
> called 
> from within the tags, and other examples showing them called 
> within .  I've always put them in the header section myself, but I 
> was wondering if one is better than the other, or is it just personal 
> preference?
> 
> Frank
> 
> --PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

Depends on your application design and/or your desired result.  If you design 
your application to do all processing before output is sent starting with 
<html>, then all your includes goes before <html>.  If you want to have the 
modular approach of including css & js files inside the <head> element, you 
don't have to worry about going back to changing every single output file when 
you decide the change your layout or javascript framework.  It also makes your 
code page a bit cleaner when you do use include in the <head>.  If you want to 
make use of chunked encoding, you can including the rest within the <body>.

Thus, include everything before <html> gives you a slight pause 'waiting for 
reply...' in the status bar before the client even begin to download anything.  
When includes are scattered all over, server processes some sends the web 
browser info, here go fetch some more (css, js, images) until the the last 
buffered output is sent </html>  (that is if your page is compliant ;)

Regards,
Tommy


--- End Message ---
--- Begin Message ---
----- Original Message ----
> From: Tommy Pham <tommy...@yahoo.com>
> To: php-gene...@lists.php.net
> Sent: Friday, September 4, 2009 4:11:31 PM
> Subject: Re: [PHP] Include Files in HTML
> 
> ----- Original Message ----
> > From: "sono...@fannullone.us" 
> > To: PHP General List 
> > Sent: Friday, September 4, 2009 12:57:08 PM
> > Subject: [PHP] Include Files in HTML
> > 
> >     In my readings, I've run across examples showing include files being 
> called 
> > from within the tags, and other examples showing them called 
> > within .  I've always put them in the header section myself, but I 
> > was wondering if one is better than the other, or is it just personal 
> > preference?
> > 
> > Frank
> > 
> > --PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> 
> Depends on your application design and/or your desired result.  If you design 
> your application to do all processing before output is sent starting with 
> , then all your includes goes before .  If you want to have the 
> modular approach of including css & js files inside the  element, you 
> don't have to worry about going back to changing every single output file 
> when 
> you decide the change your layout or javascript framework.  It also makes 
> your 
> code page a bit cleaner when you do use include in the .  If you want to 
> make use of chunked encoding, you can including the rest within the .
> 
> Thus, include everything before  gives you a slight pause 'waiting for 
> reply...' in the status bar before the client even begin to download 
> anything.  
> When includes are scattered all over, server processes some sends the web 
> browser info, here go fetch some more (css, js, images) until the the last 
> buffered output is sent   (that is if your page is compliant ;)
> 
> Regards,
> Tommy
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

Forgot to mention a few things, if your app is sophisticated enough to require 
header settings (content-type, etc), those include have to go before the 
buffered output is sent.  Also, you want to make use of chunked encoding, you 
cannot use/specify content-length in the header.


--- End Message ---
--- Begin Message ---
On Sep 4, 2009, at 5:03 PM, sono...@fannullone.us wrote:

Depends on what you are including. The only tags that can be inside the
head are <base>, <link>, <meta>, <script>, <style>,  and <title>.
Everything else is either body or prologue.

        I meant PHP includes like this one:
<?php @include_once("/home/passwords/login.php"); ?>

We know what you mean. Read the responses more carefully, as they are telling you what you need to know.

For simplification: The INCLUDE commands put the contents of the INCLUDed file into this file, just as if as you had typed it in there.

Ken

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

How do i access a variable from inside a class? ex. I want to use
$template_dir inside Template.


$template_dir = 'templates/';

class templateParser {
        var $output;
        
        function templateParser($templateFile='default_template.htm')
        {
                (file_exists($template_dir.$templateFile)) ? 
                        
$this->output=file_get_contents($template_dir.$templateFile) 
                        :
                        die('Error:Template file 
'.$template_dir.$templateFile.' not found');
        }
        
}

I run Fedora 10, apache 2.2.11 and php 5.2.9.
I get an error saying that $template_dir is undefined.

Regards
Lars Nielsen


--- End Message ---
--- Begin Message ---
Lars Nielsen wrote:
> Hi,
> 
> How do i access a variable from inside a class?

Add the following statement:
global $template_dir;

James

--- End Message ---
--- Begin Message ---
Lars Nielsen wrote:
> Hi,
> 
> How do i access a variable from inside a class? ex. I want to use
> $template_dir inside Template.
> 
> 
> $template_dir = 'templates/';
> 
> class templateParser {
>       var $output;
>       
>       function templateParser($templateFile='default_template.htm')
>       {
>               (file_exists($template_dir.$templateFile)) ? 
>                       
> $this->output=file_get_contents($template_dir.$templateFile) 
>                       :
>                       die('Error:Template file 
> '.$template_dir.$templateFile.' not found');
>       }
>       
> }
> 
> I run Fedora 10, apache 2.2.11 and php 5.2.9.
> I get an error saying that $template_dir is undefined.
> 
> Regards
> Lars Nielsen
> 

Well you have to access it as a global by either declaring it global in
the method (global $template_dir;) or by the superglobal
$GLOBALS['template_dir'].  However this is probably not the preferred
way to do it.

I would either define it as a constant define('TEMPLATE_DIR',
'templates/') or you could pass $template_dir into the class constructor
and have it set as a class var, but I prefer the constant.

-- 
Thanks!
-Shawn
http://www.spidean.com

--- End Message ---
--- Begin Message ---
Lars Nielsen wrote:
> Hi,
> 
> How do i access a variable from inside a class? ex. I want to use
> $template_dir inside Template.
> 
> 
> $template_dir = 'templates/';
> 
> class templateParser {
>       var $output;
>       
>       function templateParser($templateFile='default_template.htm')
>       {
>               (file_exists($template_dir.$templateFile)) ? 
>                       
> $this->output=file_get_contents($template_dir.$templateFile) 
>                       :
>                       die('Error:Template file 
> '.$template_dir.$templateFile.' not found');
>       }
>       
> }
> 
> I run Fedora 10, apache 2.2.11 and php 5.2.9.
> I get an error saying that $template_dir is undefined.
> 
> Regards
> Lars Nielsen
> 

Well you have to access it as a global by either declaring it global in
the method (global $template_dir;) or by the superglobal
$GLOBALS['template_dir'].  However this is probably not the preferred
way to do it.

I would either define it as a constant define('TEMPLATE_DIR',
'templates/') or you could pass $template_dir into the class constructor
and have it set as a class var, but I prefer the constant.

-- 
Thanks!
-Shawn
http://www.spidean.com

--- End Message ---
--- Begin Message ---
I cant get it to work. I will use a configuration class instead.

function templateParser($templateFile='default_template.htm')
        {
                $c = new config();
                (file_exists($c->template_dir.$templateFile)) ? 
                        
$this->output=file_get_contents($c->template_dir.$templateFile) 
                        :
                        die('Error:Template file 
'.$template_dir.$templateFile.' not found');
        }


/Lars

fre, 04 09 2009 kl. 14:49 -0700, skrev James Colannino:
> Lars Nielsen wrote:
> > Hi,
> > 
> > How do i access a variable from inside a class?
> 
> Add the following statement:
> global $template_dir;
> 
> James
> 


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

Does anyone know when the stable release of PHP6 be ready for download?  I
hear there's a lot of goodies in version 6 including built-in Caching.
Yum.  Also, will PHP ever implement the Strict mode similar to Perl's 'using
Strict'?

Thanks,
Bobby

--- End Message ---
--- Begin Message ---
On Fri, Sep 4, 2009 at 17:42, Bobby Pejman<bpej...@gmail.com> wrote:
> Hi,
>
> Does anyone know when the stable release of PHP6 be ready for download?  I
> hear there's a lot of goodies in version 6 including built-in Caching.
> Yum.  Also, will PHP ever implement the Strict mode similar to Perl's 'using
> Strict'?

    There is no date scheduled - or even well-estimated - for a stable
version of PHP6.  Best guesses are that, while it's not impossible to
say "within the next year," mid- to late-2010 or even 2011 is a
prudent expectation.

-- 
</Daniel P. Brown>
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Check out our great hosting and dedicated server deals at
http://twitter.com/pilotpig

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

> Also, will PHP ever implement the Strict mode similar to Perl's 'using
> Strict'?

Don't know if it's similar having never used Pearl, but there's always
the E_STRICT error level.

<?php
  error_reporting(E_STRICT);
?>

-- 
Richard Heyes
HTML5 graphing: RGraph - www.rgraph.net (updated 5th September)
Lots of PHP and Javascript code - http://www.phpguru.org
50% reseller discount on licensing now available - ideal for web designers

--- End Message ---
--- Begin Message ---
Sam Stelfox wrote:
> The following snippet is untested and using Ash's regex (it is accurate
> \s matches any white space). $content is what is getting stripped of the
> new lines and $filtered is the cleansed output. See if that does the
> trick for you.
> 
> $lines = str_split(PHP_EOL, $content);
> $filtered = '';
> foreach ($lines as $line) {
>    if (!preg_match('^\s*$', $line)) {
>       // Splitting on the PHP_EOL characters cause it to be removed be
> sure to put it back
>       $filtered .= $line . PHP_EOL;
>    }
> }
> 

That isn't going to work.  You missed your delimiters in the first arg
for preg_match().  It requires beginning and ending delimiters around
the regex.

I would try this

$lines = preg_split('|[\n\r]|', $content);
$filtered = '';
foreach ( $lines as $line ) {
  $txt = trim( $line );
  if ( ! empty( $txt ) ) {
      $filtered .= $line;
  }
}

It is much more intense to do the preg_match inside a loop.  You should
only do it once, then use less intense function calls inside the loop.

warning: completely untested...  have no example input you are using...


--- End Message ---
--- Begin Message ---
On Fri, 4 Sep 2009 14:58:55 +0200, ralph_def...@yahoo.de ("Ralph Deffke") wrote:

>Hi all, I'm a bit under stress, maybe somebody knows the regex on a snap.
>using PHP_EOL would be great.

Here is a function which works for files pasted from browser screens:

function clean_up($dirty_file)
        {
        $contents = file_get_contents ($dirty_file);
        if ($contents)
                {
                $c_array = explode ("\n", $contents);
                $n = count($c_array);
                $i = 0; $j = 0; while ($i < $n)
                        {
                        $line = trim($c_array[$i]);
                        if ($line != '')
                                {
                                $d_array[$j++] = $c_array[$i];
                                }
                        ++$i;
                        }
                $clean = implode ("\n",$d_array);
                $data_file = file_put_contents($data_file, $clean);
                }
        }               

The virtue of this is you don't have to know, or care, what characters are on 
the blank
lines.


--- End Message ---
--- Begin Message ---
On Fri, 04 Sep 2009 12:16:47 -0700, James Colannino wrote:

> Hey everyone.  I ran into a really weird issue that I was hoping I could
> find some clarification on.  In short, I have javascript functions that
> operate on hidden text values.  Those values may be posted, in which
> case PHP then prints them back to the page via what comes in on $_POST.
> 
> The weird thing is, I was no longer able to match substrings inside
> those hidden text values after posting via Javascript.  I banged my head
> over this for a couple hours, until I realized that the string's length
> was being increased by one after posting (I found this out in
> javascript).  Upon further investigation, I found that all instances of
> "substring\n" were being replaced by "substring(carriage return)\n"
> after post.

It may be the browser that is converting those line breaks.
>From the HTML spec.:


<http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1>:

    application/x-www-form-urlencoded
    ...
    Line breaks are represented as "CR LF" pairs (i.e., `%0D%0A').


<http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2>:

    multipart/form-data
    ...
    "CR LF" (i.e., `%0D%0A') is used to separate lines of data.


/Nisse

--- End Message ---
--- Begin Message ---
On Fri, Sep 04, 2009 at 12:16:47PM -0700, James Colannino wrote:

> Hey everyone.  I ran into a really weird issue that I was hoping I could
> find some clarification on.  In short, I have javascript functions that
> operate on hidden text values.  Those values may be posted, in which
> case PHP then prints them back to the page via what comes in on $_POST.
> 
> The weird thing is, I was no longer able to match substrings inside
> those hidden text values after posting via Javascript.  I banged my head
> over this for a couple hours, until I realized that the string's length
> was being increased by one after posting (I found this out in
> javascript).  Upon further investigation, I found that all instances of
> "substring\n" were being replaced by "substring(carriage return)\n"
> after post.
> 
> For now, I'm simply doing str_replace(chr(13), "", $_POST['value'])
> before re-inserting it into the HTML, but I was wondering why PHP is
> inserting those extra characters.

I don't know that this will help, but maybe it will provide a clue.
A textarea field will insert CRLF in its posted contents. You might
expect this to be governed by the platform the browser is running on,
but no. It inserts CRLF anyway.

Like I said, just a clue.

Paul

-- 
Paul M. Foster

--- End Message ---
--- Begin Message ---
Nisse Engström wrote:

> It may be the browser that is converting those line breaks.

Ah.  That's probably it then.  I didn't realize that was a part of the
HTML standard.  Thanks!

James

--- End Message ---

Reply via email to