php-general Digest 28 Mar 2009 04:27:29 -0000 Issue 6036

Topics (messages 290755 through 290782):

Re: Regex
        290755 by: Jesse.Hazen.arvatousa.com

Regex help please
        290756 by: Shawn McKenzie
        290759 by: haliphax
        290762 by: Shawn McKenzie

Re: flushing AJAX scripts
        290757 by: jim white
        290758 by: Andrea Giammarchi
        290760 by: Andrea Giammarchi

Re: utf-8-safe replacement for strtr()?
        290761 by: Tom Worster

Re: Multiple cookies on the same computer
        290763 by: Ken Watkins
        290764 by: Ashley Sheridan
        290767 by: Ken Watkins
        290779 by: Michael A. Peters

fpdf adding font error
        290765 by: Thodoris
        290773 by: Tony Marston

Re: php5activescript.dll
        290766 by: Jacques Manukyan

Re: Exporting text with chinese characters in CSV
        290768 by: Michael Shadle

hierarchies
        290769 by: PJ
        290770 by: Jason Pruim
        290772 by: PJ
        290774 by: Jason Pruim
        290776 by: Shawn McKenzie

pdflib greek problem
        290771 by: Thodoris
        290780 by: Michael A. Peters

validating and sanitizing input string encoding
        290775 by: Tom Worster

SESSION values show up days later!
        290777 by: Mary Anderson
        290778 by: Tom Worster
        290782 by: Paul M Foster

Sort a multi-dimensional array on a certain key followed by another key
        290781 by: TS

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 ---
Jochem,

To be more specific, the error I get when using this regex is No ending
delimiter '/' found

 
 
 
Thanks,
 
Jesse Hazen
-----Original Message-----
From: Jochem Maas [mailto:joc...@iamjochem.com] 
Sent: Thursday, March 26, 2009 11:45 PM
To: Hazen, Jesse, arvato digital services llc
Cc: php-gene...@lists.php.net
Subject: Re: [PHP] Regex

jesse.ha...@arvatousa.com schreef:
> Hi,
> 
>  
> 
> Brand new to regex. So I have a cli which runs a regex on users input,
> to make sure that only 0-9 and A-Z are accepted. It should strip
> everything else. My problem is that when you press control-Z (on
> Windows; I have not yet tested this on linux, and I will, but I would
> like this to be compatible with both OS's) it loops infinitely saying
> invalid data (because of the next method call, which decides what to
do
> based on your input). So, here is the input code. Is there a way I can
> ensure that control commands are stripped, here?
> 

there is, your control-Z is not a Z at all, and it's only printed as ^Z
so you can see it ... it's actually a non-printing char.

try this regexp for stripping control chars:

/[\x00-\x1f]+/

>  
> 
>  
> 
>  
> 
>             public function getSelection() {
> 
>  
> 
>                         $choice =
> $this->validateChoice(trim(strtoupper(fgets(STDIN))));
> 
>                         return $choice;
> 
>  
> 
>             }
> 
>  
> 
>             private function validateChoice($choice) {
> 
>  
> 
>                         $choice =
> ereg_replace("/[^0-9A-Z]/","",$choice);
> 
>                         return $choice;
> 
>  
> 
>             }
> 
>  
> 
>  
> 
>  
> 
> I have tried a ton of different things to try and fix this. Tried
> /\c.|[^0-9A-Z]/, and many variations of \c and the [^0-9A-Z], to no
> avail. I also tried using both preg_replace() as well as
ereg_replace().
> I spent a lot of time on the regex section of the PHP manual, but I am
> not finding anything. Any advise on how to accomplish this?
> 
>  
> 
>  
> 
>  
> 
> Thanks,
> 
>  
> 
> Jesse Hazen
> 
> 


--- End Message ---
--- Begin Message ---
I'm normally OK with regex, especially if I fiddle with it long enough,
however I have fiddled with this one so long that I'm either totally
missing it or it's something simple.  Does it have anything to do with
the backref, or the fact that the value of the backref has a $?  I have:

$out = '
{$sites}
<tr>
        <td>
        {Site.id}
        </td>
</tr>
{/$sites}';

And I want to capture the first {$tag}, everything in between and the
last {$/tag}.  I have tried several things and here is my current regex
that looks like it should work, but doesn't:

preg_match_all('|{\$([^}]+)}(.+)({/\1})|Us', $out, $matches);


Gives:

Array
(
    [0] => Array
        (
        )

    [1] => Array
        (
        )

    [2] => Array
        (
        )

    [3] => Array
        (
        )

)

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

--- End Message ---
--- Begin Message ---
On Fri, Mar 27, 2009 at 9:40 AM, Shawn McKenzie <nos...@mckenzies.net> wrote:
> I'm normally OK with regex, especially if I fiddle with it long enough,
> however I have fiddled with this one so long that I'm either totally
> missing it or it's something simple.  Does it have anything to do with
> the backref, or the fact that the value of the backref has a $?  I have:
>
> $out = '
> {$sites}
> <tr>
>        <td>
>        {Site.id}
>        </td>
> </tr>
> {/$sites}';
>
> And I want to capture the first {$tag}, everything in between and the
> last {$/tag}.  I have tried several things and here is my current regex
> that looks like it should work, but doesn't:
>
> preg_match_all('|{\$([^}]+)}(.+)({/\1})|Us', $out, $matches);

Shawn,

First thing I see--your first capture group doesn't include the $, and
so your final capture group will always fail given your current $out
(because it's looking for {/sites} instead of {/$sites}). Also, your
{} are outside of your capture group in \1, but inside in \3. Here's
what I came up with:

$out = '
{$sites}
<tr>
       <td>
       {Site.id}
       </td>
</tr>
{/$sites}';
$matches = array();
preg_match_all('#{(\$[^}]+)}(.*?){(/\1)}#s', $out, $matches);
print_r($matches);

Produces this:

Array
(
    [0] => Array
        (
            [0] => {$sites}
<tr>
       <td>
       {Site.id}
       </td>
</tr>
{/$sites}
        )

    [1] => Array
        (
            [0] => $sites
        )

    [2] => Array
        (
            [0] =>
<tr>
       <td>
       {Site.id}
       </td>
</tr>

        )

    [3] => Array
        (
            [0] => /$sites
        )

)

Keep in mind, I had to view the page source in order to see the HTML
tags, but it showed me everything I expected to see.

HTH,

-- 
// Todd

--- End Message ---
--- Begin Message ---
haliphax wrote:
> On Fri, Mar 27, 2009 at 9:40 AM, Shawn McKenzie <nos...@mckenzies.net> wrote:
>> I'm normally OK with regex, especially if I fiddle with it long enough,
>> however I have fiddled with this one so long that I'm either totally
>> missing it or it's something simple.  Does it have anything to do with
>> the backref, or the fact that the value of the backref has a $?  I have:
>>
>> $out = '
>> {$sites}
>> <tr>
>>        <td>
>>        {Site.id}
>>        </td>
>> </tr>
>> {/$sites}';
>>
>> And I want to capture the first {$tag}, everything in between and the
>> last {$/tag}.  I have tried several things and here is my current regex
>> that looks like it should work, but doesn't:
>>
>> preg_match_all('|{\$([^}]+)}(.+)({/\1})|Us', $out, $matches);
> 
> Shawn,
> 
> First thing I see--your first capture group doesn't include the $, and
> so your final capture group will always fail given your current $out
> (because it's looking for {/sites} instead of {/$sites}). Also, your
> {} are outside of your capture group in \1, but inside in \3. Here's
> what I came up with:
> 
> $out = '
> {$sites}
> <tr>
>        <td>
>        {Site.id}
>        </td>
> </tr>
> {/$sites}';
> $matches = array();
> preg_match_all('#{(\$[^}]+)}(.*?){(/\1)}#s', $out, $matches);
> print_r($matches);
> 
> Produces this:
> 
> Array
> (
>     [0] => Array
>         (
>             [0] => {$sites}
> <tr>
>        <td>
>        {Site.id}
>        </td>
> </tr>
> {/$sites}
>         )
> 
>     [1] => Array
>         (
>             [0] => $sites
>         )
> 
>     [2] => Array
>         (
>             [0] =>
> <tr>
>        <td>
>        {Site.id}
>        </td>
> </tr>
> 
>         )
> 
>     [3] => Array
>         (
>             [0] => /$sites
>         )
> 
> )
> 
> Keep in mind, I had to view the page source in order to see the HTML
> tags, but it showed me everything I expected to see.
> 
> HTH,
> 

Yes, thank you.  I was fiddling before I got your post and I came up
with roughly the same.

preg_match_all('|{(\$[^}]+)}(.+){(/\1)}|Us', $out, $matches);

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

--- End Message ---
--- Begin Message --- My page submits the AJAX request to complete a report that takes some time, and upon completion stores results in a database. A second AJAX request polls every 5 seconds and queries the database if the report is ready. This hopefully will get around any timeout problems I am having with a long running request, and seems to be working. It looks like I can accept the default behavior for now. I don't depend on getting a response from the original request, but is there a point where the AJAX response script will be stopped either by Apache or PHP before it can insert into the database?

Jim


Andrea Giammarchi wrote:
Some browser would like to receive at list N characters (bytes) even if
you force the flush, before the browser will show those characters.
In
any case, the Ajax request will not be completed until its readyState
will be 4, which means the page execution on the server has finished
(released, php has gone, flush or not flush)
For a task like this one you have few options:
 1 - launch  new thread if your host is able to do it
 2 - use a Comet like response (for php I wrote Phico some while ago)
In any case, I hope this stressful operation cannot be performed from thousand 
of users or you can say bye bye to the service.
Alternatives:
 1 - optimize your database
 2 - delegate the job once a time rather than every click (cronjob)
 3 - if the bottleneck is PHP, create an extension in C to perform the same task

Hope this help.

Regards

P.S.
Internet Explorer a part, you can read the responseText on readystate 3
which will be called different time (most likely for each flush).
If IE is not your target, you could consider this opportunity to read the sent 
stream so far.

Date: Fri, 27 Mar 2009 08:49:35 +1100
From: dmag...@gmail.com
To: jbw2...@earthlink.net
CC: php-gene...@lists.php.net
Subject: Re: [PHP] flushing AJAX scripts

jim white wrote:
I am using jQuery AJAX request to run a script that can take several minutes to create a report. I want to start the script and immediately echo a response to close the connection and then let the script complete a report which I can get later. I have tried several thing such as

ob_start();
echo json_encode(array("time"=>$now, "message"=>"Report has started running!"));
ob_end_flush();
Try something like this

echo "something";
flush();

without the ob* stuff.

--
Postgresql & php tutorials
http://www.designmagick.com/


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


_________________________________________________________________
Drag n’ drop—Get easy photo sharing with Windows Live™ Photos.

http://www.microsoft.com/windows/windowslive/products/photos.aspx


--
James (Jim) B. White
tel: (919)-380-9615
homepage: http://jimserver.net/
--- End Message ---
--- Begin Message ---
Sorry, Kim, but why on earth you are polling with a second request to know when 
the first one has finished?
I mean, when the first request inserts data in the database that's it, you'll 
manage the end of the request.

$A --->  do stuff; do stuff; do stuff; report ready;
$B ---> report ready?
$B ---> report ready?
$B ---> report ready?
$B ---> report ready?
report ready; ---> notification to A
$B ---> report ready;

the report ready, if it is when $A request has been finished, will be in $A, 
the polling via $B is absolutely useless, imo.

There is no timeout from Ajax, it simply keep waiting, but obviously if your 
PHP has max_execution_time 30 seconds and the script execution takes more than 
30 seconds there's no polling that could save you.

The same if the user closes the browser, connection lost, bye bye response.

To have a notice, you need Comet, try out Phico but still, a page that requires 
that much is not suitable for the web. Report creation should be a cronjob in a 
separed thread if it is that stressful.

Regards

> Date: Fri, 27 Mar 2009 10:47:10 -0400
> From: jbw2...@earthlink.net
> To: an_...@hotmail.com
> CC: php-gene...@lists.php.net
> Subject: Re: RE: [PHP] flushing AJAX scripts
> 
> My page submits the AJAX request to complete a report that takes some 
> time, and upon completion stores results in a database. A second AJAX 
> request polls every 5 seconds and queries the database if the report is 
> ready. This hopefully will get around any timeout problems I am having 
> with a long running request, and seems to be working. It looks like I 
> can accept the default behavior for now. I don't depend on getting a 
> response from the original request, but is there a point where the AJAX 
> response script will be stopped either by Apache or PHP before it can 
> insert into the database?
> 
> Jim

_________________________________________________________________
News, entertainment and everything you care about at Live.com. Get it now!
http://www.live.com/getstarted.aspx

--- End Message ---
--- Begin Message ---
Sorry Jim, I meant Jim when I wrote Kim ... and 
Phico: 
http://webreflection.blogspot.com/2008/04/phomet-changes-name-so-welcome-phico.html

Regards

> From: an_...@hotmail.com
> To: php-gene...@lists.php.net
> Date: Fri, 27 Mar 2009 15:55:28 +0100
> Subject: RE: [PHP] flushing AJAX scripts
> 
> 
> Sorry, Kim, but why on earth you are polling with a second request to know 
> when the first one has finished?
> I mean, when the first request inserts data in the database that's it, you'll 
> manage the end of the request.
> 
> $A --->  do stuff; do stuff; do stuff; report ready;
> $B ---> report ready?
> $B ---> report ready?
> $B ---> report ready?
> $B ---> report ready?
> report ready; ---> notification to A
> $B ---> report ready;
> 
> the report ready, if it is when $A request has been finished, will be in $A, 
> the polling via $B is absolutely useless, imo.
> 
> There is no timeout from Ajax, it simply keep waiting, but obviously if your 
> PHP has max_execution_time 30 seconds and the script execution takes more 
> than 30 seconds there's no polling that could save you.
> 
> The same if the user closes the browser, connection lost, bye bye response.
> 
> To have a notice, you need Comet, try out Phico but still, a page that 
> requires that much is not suitable for the web. Report creation should be a 
> cronjob in a separed thread if it is that stressful.
> 
> Regards
> 
> > Date: Fri, 27 Mar 2009 10:47:10 -0400
> > From: jbw2...@earthlink.net
> > To: an_...@hotmail.com
> > CC: php-gene...@lists.php.net
> > Subject: Re: RE: [PHP] flushing AJAX scripts
> > 
> > My page submits the AJAX request to complete a report that takes some 
> > time, and upon completion stores results in a database. A second AJAX 
> > request polls every 5 seconds and queries the database if the report is 
> > ready. This hopefully will get around any timeout problems I am having 
> > with a long running request, and seems to be working. It looks like I 
> > can accept the default behavior for now. I don't depend on getting a 
> > response from the original request, but is there a point where the AJAX 
> > response script will be stopped either by Apache or PHP before it can 
> > insert into the database?
> > 
> > Jim
> 
> _________________________________________________________________
> News, entertainment and everything you care about at Live.com. Get it now!
> http://www.live.com/getstarted.aspx

_________________________________________________________________
Drag n’ drop—Get easy photo sharing with Windows Live™ Photos.

http://www.microsoft.com/windows/windowslive/products/photos.aspx

--- End Message ---
--- Begin Message ---
On 3/26/09 11:36 AM, "Nisse Engström" <news.nospam.0ixbt...@luden.se> wrote:

> On Wed, 25 Mar 2009 11:32:42 +0100, Nisse Engström wrote:
> 
>> On Tue, 24 Mar 2009 08:15:35 -0400, Tom Worster wrote:
>> 
>>> strtr() with three parameters is certainly unsafe. but my tests are showing
>>> that it may be ok with two parameters if the strings in the second parameter
>>> are well formed utf-8.
>>> 
>>> does anyone know more? can confirm or contradict?
>> 
>> The two-argument version of strtr() should work fine
>> since there are no collisions in utf-8 such that part
>> of one character matches part of a different character.
> 
> Oops. I meant to write that one complete character does
> not match any part of any other character. If a string
> of one or more utf-8 characters match a utf-8 text, it
> matches exactly those characters in the text. If that
> makes sense...

yes.

my conclusion is that 2-param strtr is safe if the subject text and
parameter strings are valid utf-8.



--- End Message ---
--- Begin Message ---
>>> On 3/27/2009 at 10:19 AM, in message <6f.57.30978.d60ec...@pb1.pair.com>, 
>>> Shawn McKenzie <nos...@mckenzies.net> wrote:
>> Optionally, I just thought that if this was too much for them to
>> do/remember, they could have their own bookmarks, like "Dad - Yoursite"
>> (http://www.yoursite.com/index.php?person=dad) and Mom - Yoursite
>> (http://www.yoursite.com/index.php?person=mom) and set the
>> session/cookie or whatever you're doing based on $_GET['person'].
>> 
>> I would still opt for the login though, even if not secure.
>> 
>>
>No, they use their own cookies so if you want to do it that way, use:
>$_SERVER['HTTP_USER_AGENT'] and set the cookie based upon the browser.
>
>Another thought I had was if you can add domain aliases,
>dad.yoursite.com and mom.yoursite.com, then they will each have
>different cookies.
 
Shawn -
 
Yes, domain aliases sound good too. OK, you've given me a couple of good 
suggestions, and one of them should suit me :)
Thanks much.
 
Ken

 

--- End Message ---
--- Begin Message ---
On Fri, 2009-03-27 at 09:59 -0400, Ken Watkins wrote:
> >>> On 3/26/2009 at 10:24 PM, in message 
> >>> <0a88dc6e-0655-4565-b9a7-e21337fc0...@bluerodeo.com>, dg 
> >>> <dane...@bluerodeo.com> wrote:
> 
> On Mar 26, 2009, at 7:14 PM, Ken Watkins wrote:
> 
> >> To keep up with their identities, I created a script for each family  
> >> member to run (dad.php, mom.php, etc.), and it sets a cookie on each  
> >> computer and uses sessions so I know who is connecting.
> 
> >Each family member only uses her/his own page?  Maybe set a unique  
> >cookie name based on each page?
> 
> Hi.
> 
> No, they all go to a common page. I may have to take Shawn's suggestion and 
> just have them login if I can't figure another way to do it.
> 
> Thanks.
> Ken
> 
> 
> 
> 
You could have a landing page to the site, that consists of image links
(you could use their photo for this?) and each link is in the order of
page.php?person=mum etc. That would require an extra click, but no
typing for a login, and should make the unique person process a bit more
intuitive.


Ash
www.ashleysheridan.co.uk


--- End Message ---
--- Begin Message ---
>>> On 3/27/2009 at 11:15 AM, in message 
>>> <1238166938.3522.5.ca...@localhost.localdomain>, Ashley Sheridan 
>>> <a...@ashleysheridan.co.uk> wrote:
On Fri, 2009-03-27 at 09:59 -0400, Ken Watkins wrote:
> >>> On 3/26/2009 at 10:24 PM, in message 
> >>> <0a88dc6e-0655-4565-b9a7-e21337fc0...@bluerodeo.com>, dg 
> >>> <dane...@bluerodeo.com> wrote:
>> 
>> On Mar 26, 2009, at 7:14 PM, Ken Watkins wrote:
>> 
>> >> To keep up with their identities, I created a script for each family  
>> >> member to run (dad.php, mom.php, etc.), and it sets a cookie on each  
>> >> computer and uses sessions so I know who is connecting.
>> 
>> >Each family member only uses her/his own page?  Maybe set a unique  
>> >cookie name based on each page?
>> 
>> Hi.
>> 
>> No, they all go to a common page. I may have to take Shawn's suggestion and 
>> just have them login if I can't figure another way to do it.
>> 
>> Thanks.
>> Ken
>> 
>> 
>> 
>> 
>You could have a landing page to the site, that consists of image links
>(you could use their photo for this?) and each link is in the order of
>page.php?person=mum etc. That would require an extra click, but no
>typing for a login, and should make the unique person process a bit more
>intuitive.
>
>
>Ash
>www.ashleysheridan.co.uk 
 
Hi Ash.
 
Hey, I like it. Clicking beats typing in my book. Thanks!
 
Ken

--- End Message ---
--- Begin Message ---
Ken Watkins wrote:
Hi all.

Newbie here.

I have set up a blog site where my family creates posts and they get emailed to 
members of the family. To keep up with their identities, I created a script for 
each family member to run (dad.php, mom.php, etc.), and it sets a cookie on 
each computer and uses sessions so I know who is connecting. It works great 
unless I want to share a computer between two users.

I thought I had a solution: install both Firefox and IE on the same computer 
and set two different cookies. But this doesn't seem to work. My question is: 
Is it possible to set one cookie for IE and another for Firefox so that, 
depending on which browser is used, I can tell who is connecting to the blog? 
If this is not possible, is there another easy way to do it?

Thanks for your help.

- Ken Watkins


Why not just use session cookies that expire as soon as a session is over (browser quits) and use a login?
--- End Message ---
--- Begin Message ---
Hello gang,
I know this is not an fpdf mailing list but if anyone has experience on the matter please help. I am working on a pdf generation part of a project and I am using fpdf to generate them.

The content of the pdf needs to be in greek. But I am having difficulties to get the pdf generated properly. This means that I can't see the greek in the pdf file that is generated. I have tried to set the encoding to non-UTF since fpdf doesn't support UTF-8 but the problem still remains. As a second solution I am trying to add new fonts with the ISO-8859-7 encoding but it doesn't work as expected. The font is not being although I am following the fpdf's directions step-by-step.


Does anybody know another way to generate pdf files with greek properly or can help me with the fpdf??

Thanks in advance.

--
Thodoris


--- End Message ---
--- Begin Message ---
If you want to use UTF-8 fonts with FPDF then switch to TCPDF 
(www.tcpdf.org)

-- 
Tony Marston
http://www.tonymarston.net
http://www.radicore.org

"Thodoris" <t...@kinetix.gr> wrote in message 
news:49ccee54.80...@kinetix.gr...
> Hello gang,
>    I know this is not an fpdf mailing list but if anyone has experience on 
> the matter please help. I am working on a pdf generation part of a project 
> and I am using fpdf to generate them.
>
>    The content of the pdf needs to be in greek. But I am having 
> difficulties to get the pdf generated properly. This means that I can't 
> see the greek in the pdf file that is generated. I have tried to set the 
> encoding to non-UTF since fpdf doesn't support UTF-8 but the problem still 
> remains. As a second solution I am trying to add new fonts with the 
> ISO-8859-7 encoding but it doesn't work as expected. The font is not being 
> although I am following the fpdf's directions step-by-step.
>
>
> Does anybody know another way to generate pdf files with greek properly or 
> can help me with the fpdf??
>
> Thanks in advance.
>
> -- 
> Thodoris
> 



--- End Message ---
--- Begin Message --- The site is under maintenance. You could wait or download it from: http://kromann.info/download.php?strFolder=php5_1-Release_TS&strIndex=PHP5_1

Note that I do not know of the validity of that site so have your antivirus program ready.

-- Jacques Manukyan


Robert Johnson wrote:
I've been trying to locate this file and could not find it in the downloads area and got this message when I tried - http://pecl4win.php.net/ "The pecl4win build box is temporarily out of service. We're preparing a new build system. "

Any suggestions?
Thanks.


--- End Message ---
--- Begin Message --- The php script language has no bearing on the output unless you have characters In the php file itself.

We had some issue like this at work. They found a way using iconv to to it but had to change because redhats iconv isn't updated. They do something with saving the output to a utf8 encoded page and then sending it out or something. I assume you're trying to have this be used in excel?

On Mar 27, 2009, at 2:59 AM, Ashley Sheridan <a...@ashleysheridan.co.uk> wrote:

On Fri, 2009-03-27 at 17:40 +0800, Ai Leen wrote:
Hi Everyone,

I need to export data from database with UTF-8 encoding to an csv file. I am
outputing html tables with the Content Type set to msexcel.

The chinese texts came out as symbols. I tried
using mb_convert_encoding the text from UTF-8 to UTF-16LE
iconv from UTF8 to gb2312
iconv from UTF-8 to cp1252

Can anyone who has successfully export english text with chinese characters
mixed in to CSV help?

Thank you very much,
Ai Leen


Strictly speaking, a csv file won't contain HTML markup, so you should
probably just stick to delimited value lines in your file. Have you
tried changing the Content Type to text/plain and then save your PHP
script as utf-8. It's this last one that sometimes causes problems, as I
believe it is needed for PHP to correctly output utf-8.


Ash
www.ashleysheridan.co.uk


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


--- End Message ---
--- Begin Message ---
I do have a bit of a problem which has not been clearly explained in
the suggestions to my previous posts and that is the question of
hierarchies. I have not yet understood how to include a file anywhere in
a directory tree and have it point to the right file which may be in the
top directory or, most likely, in a /lib/ directory from the file that
is including.
Any suggestions, or should I just make myself small and
wait for the rotten eggs and spoiled tomatoes to come raining down on my
head? :'(

-- 
unheralded genius: "A clean desk is the sign of a dull mind. "
-------------------------------------------------------------
Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


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


PJ wrote:
I do have a bit of a problem which has not been clearly explained in
the suggestions to my previous posts and that is the question of
hierarchies. I have not yet understood how to include a file anywhere in
a directory tree and have it point to the right file which may be in the
top directory or, most likely, in a /lib/ directory from the file that
is including.
Any suggestions, or should I just make myself small and
wait for the rotten eggs and spoiled tomatoes to come raining down on my
head? :'(

Are you talking about having a file structure such as:

/home
/include
/webroot
/->images
/->css
/->java

And you want to include a file from the include folder which is above the webroot, so doesn't have access to it?

If that's the case... you just need to set the path such as: ini_set("include_path", "/home/include");
then in your PHP file you should be able to: include("mysupperfile.php");
and it should work :)


--- End Message ---
--- Begin Message ---
Jason Pruim wrote:
>
>
> PJ wrote:
>> I do have a bit of a problem which has not been clearly explained in
>> the suggestions to my previous posts and that is the question of
>> hierarchies. I have not yet understood how to include a file anywhere in
>> a directory tree and have it point to the right file which may be in the
>> top directory or, most likely, in a /lib/ directory from the file that
>> is including.
>> Any suggestions, or should I just make myself small and
>> wait for the rotten eggs and spoiled tomatoes to come raining down on my
>> head? :'(
>>
>>   
> Are you talking about having a file structure such as:
>
> /home
> /include
> /webroot
> /->images
> /->css
> /->java
>
> And you want to include a file from the include folder which is above
> the webroot, so doesn't have access to it?
>
> If that's the case... you just need to set the path such as:
> ini_set("include_path", "/home/include");
> then in your PHP file you should be able to: include("mysupperfile.php");
> and it should work :)
>
>
Not quite, but interesting option. This would be fine on my local
intranet, if needed; but I don't think this would be allowed on a
virtual hosted site.

Actually, my problem is to use a header.php (for example) in pages in
the webroot directory or any directory within (or under) webroot:

/ <---- webroot
/site1
   /files
   /images
   /lib
   /more files
   /admin
      /other_files
      /still_others
/site2
/site3
files
files
files...

I have the header.php file in /lib .
If I put include dirname(_FILE_)."/lib/header.php"; in a file under
/site1, the header is displayed.
If I put the same include statement in a file under /site1/files, the
header is not displayed; if I change the include to
..."/../lib/header.php"; it then works.
I want to be able to point to the include to the same file in the same
directory without having to change the include directive.

-- 
unheralded genius: "A clean desk is the sign of a dull mind. "
-------------------------------------------------------------
Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


--- End Message ---
--- Begin Message ---
PJ wrote:
Jason Pruim wrote:
PJ wrote:
I do have a bit of a problem which has not been clearly explained in
the suggestions to my previous posts and that is the question of
hierarchies. I have not yet understood how to include a file anywhere in
a directory tree and have it point to the right file which may be in the
top directory or, most likely, in a /lib/ directory from the file that
is including.
Any suggestions, or should I just make myself small and
wait for the rotten eggs and spoiled tomatoes to come raining down on my
head? :'(

Are you talking about having a file structure such as:

/home
/include
/webroot
/->images
/->css
/->java

And you want to include a file from the include folder which is above
the webroot, so doesn't have access to it?

If that's the case... you just need to set the path such as:
ini_set("include_path", "/home/include");
then in your PHP file you should be able to: include("mysupperfile.php");
and it should work :)


Not quite, but interesting option. This would be fine on my local
intranet, if needed; but I don't think this would be allowed on a
virtual hosted site.

Actually, my problem is to use a header.php (for example) in pages in
the webroot directory or any directory within (or under) webroot:

/ <---- webroot
/site1
   /files
   /images
   /lib
   /more files
   /admin
      /other_files
      /still_others
/site2
/site3
files
files
files...

I have the header.php file in /lib .
If I put include dirname(_FILE_)."/lib/header.php"; in a file under
/site1, the header is displayed.
If I put the same include statement in a file under /site1/files, the
header is not displayed; if I change the include to
..."/../lib/header.php"; it then works.
I want to be able to point to the include to the same file in the same
directory without having to change the include directive.

I actually use that on a shared host... Really depends on the host though... My actual file path is something more like:

/home/
   /myusername/
   /include/
   /public_html/ <---- Web root
      /file.php
      /another folder/


So all my files are inside my home folder on the server, but nothing outside of public_html is accessible from the web.

As for the rest... I haven't started using dir(__FILE__) stuff yet so I won't be any help with that...



--- End Message ---
--- Begin Message ---
PJ wrote:
> Not quite, but interesting option. This would be fine on my local
> intranet, if needed; but I don't think this would be allowed on a
> virtual hosted site.
> 
> Actually, my problem is to use a header.php (for example) in pages in
> the webroot directory or any directory within (or under) webroot:
> 
> / <---- webroot
> /site1
>    /files
>    /images
>    /lib
>    /more files
>    /admin
>       /other_files
>       /still_others
> /site2
> /site3
> files
> files
> files...
> 
> I have the header.php file in /lib .
> If I put include dirname(_FILE_)."/lib/header.php"; in a file under
> /site1, the header is displayed.
> If I put the same include statement in a file under /site1/files, the
> header is not displayed; if I change the include to
> ..."/../lib/header.php"; it then works.
> I want to be able to point to the include to the same file in the same
> directory without having to change the include directive.
> 

The problem is with how you are organizing your app.  Includes are
relative to the first file that's loaded, so if the first file that is
loaded is in /site1/files/ then you have to know where /lib/header.php
is from there.

Most people don't load individual files (at least not from different
dirs) as you seem to be doing.  My advice is to always load the same
file first from the root dir and then include your other files.  Then
those files will include header.php relative to the root dir.

*** Example:

(/site1/index.php)
<?php
//based upon some criteria
include('files/yourfile.php');
?>

(/site1/files/yourfile.php)
<?php
include('lib/header.php');
?>

*** Better Example:

(/site1/index.php)
<?php
include('lib/header.php');
//based upon some criteria
include('files/yourfile.php');
?>

(/site1/files/yourfile.php)
<?php
//content that is original to this file
?>


Above when I say "based upon some criteria", it would be something like
this (example only):

switch ($_GET['file']) {
        case 'yourfile':
                include('files/yourfile.php');
                break;

        case 'somefile':
                include('more_files/somefile.php');
                break;
}

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

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

Hi,
   I am trying the following code to generate a pdf:

   try {
       // Create a new pdf handler
       $pdf = new PDFlib();

       //  open new PDF file
       if ($pdf->begin_document("", "") == 0) {
           die("Error: " . $p->get_errmsg());
       }

       // Set some info to the new pdf
       $pdf->set_info("Creator", "Test");
       $pdf->set_info("Author", "Test");
       $pdf->set_info("Title", "Test");
// Start the page
       $pdf->begin_page_ext(595, 842, "");
// Load the documents font and set the details
       $font = $pdf->load_font("Times-Roman", "iso8859-7", "");
       $pdf->setfont($font,24.0);
       $pdf->set_parameter('autospace',TRUE);
// Set the position inside the document
       $pdf->set_text_pos(50, 700);
// Now start to show the data
       $str = 'Αυτό είναι ένα τεστ.';
       mb_convert_variables('ISO-8859-7','UTF-8',$str);
       $pdf->show($str);
// End the page and the document
       $pdf->end_page_ext("");
       $pdf->end_document("");
// Get the document from the buffer find it's length
       $buf = $pdf->get_buffer();
       $len = strlen($buf);
// And finally print it out to the browser
       header("Content-type: application/pdf");
       header("Content-Length: $len");
       header("Content-Disposition: inline; filename=hello.pdf");
       print $buf;
} catch (PDFlibException $e) {
       die("PDFlib exception occurred in hello sample:\n" .
   "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " .
       $e->get_errmsg() . "\n");
   }
   catch (Exception $e) {
       die($e);
   }

Although greek are printed normally the characters are overlapping on each other. The script in encoded in UTF-8.

Does anybody have any suggestions on this? Please any help would be appreciated.

--
Thodoris


--- End Message ---
--- Begin Message ---
Thodoris wrote:

Hi,
   I am trying the following code to generate a pdf:

   try {
       // Create a new pdf handler
       $pdf = new PDFlib();

       //  open new PDF file
       if ($pdf->begin_document("", "") == 0) {
           die("Error: " . $p->get_errmsg());
       }

       // Set some info to the new pdf
       $pdf->set_info("Creator", "Test");
       $pdf->set_info("Author", "Test");
       $pdf->set_info("Title", "Test");
             // Start the page
       $pdf->begin_page_ext(595, 842, "");
             // Load the documents font and set the details
       $font = $pdf->load_font("Times-Roman", "iso8859-7", "");
       $pdf->setfont($font,24.0);
       $pdf->set_parameter('autospace',TRUE);
             // Set the position inside the document
       $pdf->set_text_pos(50, 700);
             // Now start to show the data
       $str = 'Αυτό είναι ένα τεστ.';
       mb_convert_variables('ISO-8859-7','UTF-8',$str);
       $pdf->show($str);
             // End the page and the document
       $pdf->end_page_ext("");
       $pdf->end_document("");
             // Get the document from the buffer find it's length
       $buf = $pdf->get_buffer();
       $len = strlen($buf);
             // And finally print it out to the browser
       header("Content-type: application/pdf");
       header("Content-Length: $len");
       header("Content-Disposition: inline; filename=hello.pdf");
       print $buf;
           }
     catch (PDFlibException $e) {
       die("PDFlib exception occurred in hello sample:\n" .
   "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " .
       $e->get_errmsg() . "\n");
   }
   catch (Exception $e) {
       die($e);
   }

Although greek are printed normally the characters are overlapping on each other. The script in encoded in UTF-8.

Does anybody have any suggestions on this? Please any help would be appreciated.


LaTeX has some greek stuff that works fairly well - though you have to use one of the fonts encoded for LaTeX.

If you mean to have a web app generate the PDF you'll have to output to .tex and then use a shell command to compile the document, but it is a solution that is fairly well tested for creation of Greek (monotonic and polytonic) PDF documents.

I know that isn't what you asked, but in case there isn't a PDFLib solution to the typesetting issue, I suspect an application designed for typesetting will give better results anyway.
--- End Message ---
--- Begin Message ---
the article at http://devlog.info/2008/08/24/php-and-unicode-utf-8, among
other web pages, suggests checking for valid utf-8 string encoding using
(strlen($str) && !preg_match('/^.{1}/us', $str)). however, another article,
http://www.phpwact.org/php/i18n/charsets, says this cannot be trusted. i
work exclusively with mbstring environments so i could use
mb_check_encoding().

which leads to the question of what to do if mb_check_encoding() indicates
bad input?

i don't want to throw the form back to the user because most of my users
will not be able to rectify the input. errors in the data are undesirable,
of course, but in my application, no disastrous. so i'm inclined to the
approach mentioned here:
http://blog.liip.ch/archive/2005/01/24/how-to-get-rid-of-invalid-utf-8-chara
cters.html, i.e. iconv("UTF-8","UTF-8//IGNORE",$t), which will quietly
eliminate badly formed characters and move on (iconv will throw a notice on
bad utf-8).

so i'm considering using a function like this:

function clean_input(&$a) {
    if ( is_array($a) && !empty($a) )
        foreach ($a as $k => &$v)
            clean_input($v);
    elseif ( is_string($a) && !mb_check_encoding($a, 'UTF-8'))
        $a = iconv('UTF-8', 'UTF-8//IGNORE', $a);
}

and calling it on $_POST or $_GET as appropriate at the stop of any script
that uses those superglobals.

it seems a bit lazy to me but that's my nature and i think this might be
good enough. any thoughts?



--- End Message ---
--- Begin Message ---
Hi all,
I use session variables to store values from one page to another on my website. Alas, sometimes, but not always, the values persist from one invocation of the script to another! Just how, exactly, do I make them go away when a user exits the program? I assume my users will not always be logging out explicitly.
   Thanks.
    maryfran

--- End Message ---
--- Begin Message ---
On 3/27/09 5:39 PM, "Mary Anderson" <maryf...@demog.berkeley.edu> wrote:

> Hi all,
>     I use session variables to store values from one page to another on
> my website.
>     Alas, sometimes, but not always, the values persist from one
> invocation of the script to another!
>     Just how, exactly, do I make them go away when a user exits the
> program? I assume my users will not always be logging out explicitly.

if this is on a server with low traffic, e.g. a development or test server,
it could be because of the way the garbage collector works. it's explained
in the manual.



--- End Message ---
--- Begin Message ---
On Fri, Mar 27, 2009 at 02:39:22PM -0700, Mary Anderson wrote:

> Hi all,
>    I use session variables to store values from one page to another on
> my website.
>    Alas, sometimes, but not always, the values persist from one
> invocation of the script to another!
>    Just how, exactly, do I make them go away when a user exits the
> program? I assume my users will not always be logging out explicitly.
>    Thanks.
>     maryfran

Unset the variable. Session variables (as far as I know) will persist as
long as the user keeps open his browser, or until they time out. But you
can do unset($_SESSION['myvar']) to unset a particular variable at any
time (assuming you have previously called session_start()).

Paul

-- 
Paul M. Foster

--- End Message ---
--- Begin Message ---
Ok so, I have an array

[0(index)][1st key][2nd key]

Basically I don't care about the index. As a matter of fact I'd prefer it
reset to still be in order afterwards.

However, I need to sort the 1st key and keep correlation w the second key.
Then sort on the second key.

I have video volumes and scenes like 

[0][110][1]
[1][110][3]
[2][110][2]
[3][110][4]

Any help would be much appreciated.


--- End Message ---

Reply via email to