php-general Digest 12 Oct 2003 18:37:06 -0000 Issue 2351

Topics (messages 165880 through 165916):

Re: Detecting devices i.e. PDA, Mobile
        165880 by: Justin French
        165885 by: Tom Rogers
        165896 by: Justin French
        165897 by: Raditha Dissanayake

newbie question
        165881 by: Wang Feng
        165882 by: Eugene Lee
        165883 by: Wang Feng
        165890 by: Eugene Lee
        165906 by: Curt Zirzow
        165907 by: Wang Feng
        165908 by: Robert Cummings
        165913 by: Wang Feng

Re: Age from date field?
        165884 by: Eugene Lee
        165902 by: Curt Zirzow

I can't make 'read_tag.php' file
        165886 by: Bas
        165901 by: Manuel Vázquez Acosta
        165904 by: Curt Zirzow

https detection
        165887 by: Rosen
        165888 by: Tom Rogers
        165889 by: Rosen
        165891 by: Tom Rogers
        165892 by: Eugene Lee
        165893 by: Eugene Lee
        165894 by: Tom Rogers
        165895 by: Eugene Lee
        165898 by: Tom Rogers
        165905 by: Curt Zirzow

xml in php5.0.0beta1
        165899 by: Dennis Heuer
        165903 by: Bertrand Moulard

Re: PNG to GIF conversion
        165900 by: Comex

awful newbie question
        165909 by: Paul Freedman
        165910 by: Marek Kilimajer

levenshtein - comparing strings?
        165911 by: Duncan

Output control - IE problem with flush()
        165912 by: Duncan

mail() php in message
        165914 by: Onno Kuipers
        165916 by: Matthias Wulkow

Problem with session_destroy() don't work
        165915 by: Kostas

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 --- On Sunday, October 12, 2003, at 12:02 PM, Manuel Vázquez Acosta wrote:

Take a look at what is printed by:

var_dump($_SERVER);

Maybe the HTTP_USER_AGENT can lead you to somewhere out of this problem.

Manu.

"Shaun" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Hi,

I have created an online system, and have created a WAP version, and am
currently crreating a PDA version. What I wuold like to to do is give out
the same URL instead of domain.com for normal use, domain.com/wap/ or
domain.com/pda/. Is there a way of detecting what device is loading the
site
and redirect them accordingly?

Thanks for your help


Manuel, Shaun,

$_SERVER['HTTP_USER_AGENT'] (just like anything else from the client side) can't be trusted to either exist, or to be correct. Some user agents don't set this value, and it's quite easy for it to be faked. More to the point, there's no way you can possibly account for all possible user agents out there... perhaps only the popular ones.

So, $_SERVER['HTTP_USER_AGENT'] is a good starting point or method for guessing where to send people, but it's not fail safe AT ALL.


I think the fail safe way is to create pages which are standards compliant (XHTML strict) and use CSS for all styling/presentation, which means your pages will accessible via the largest possible number of viewing devices, like PDA, WAP, text-to-speech, desktop browsers, Web TV, etc.


The move away from table based layouts and poorly accessible webpages is a big one, but not THAT big :)


Justin

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

Sunday, October 12, 2003, 4:53:27 PM, you wrote:
JF> On Sunday, October 12, 2003, at 12:02  PM, Manuel Vázquez Acosta wrote:

>> Take a look at what is printed by:
>>
>> var_dump($_SERVER);
>>
>> Maybe the HTTP_USER_AGENT can lead you to somewhere out of this 
>> problem.
>>
>> Manu.
>>
>> "Shaun" <[EMAIL PROTECTED]> wrote in message
>> news:[EMAIL PROTECTED]
>>> Hi,
>>>
>>> I have created an online system, and have created a WAP version, and 
>>> am
>>> currently crreating a PDA version. What I wuold like to to do is give 
>>> out
>>> the same URL instead of domain.com for normal use, domain.com/wap/ or
>>> domain.com/pda/. Is there a way of detecting what device is loading 
>>> the
>> site
>>> and redirect them accordingly?
>>>
>>> Thanks for your help


JF> Manuel, Shaun,

JF> $_SERVER['HTTP_USER_AGENT'] (just like anything else from the client 
JF> side) can't be trusted to either exist, or to be correct.  Some user 
JF> agents don't set this value, and it's quite easy for it to be faked.  
JF> More to the point, there's no way you can possibly account for all 
JF> possible user agents out there... perhaps only the popular ones.

JF> So, $_SERVER['HTTP_USER_AGENT'] is a good starting point or method for 
JF> guessing where to send people, but it's not fail safe AT ALL.


JF> I think the fail safe way is to create pages which are standards 
JF> compliant (XHTML strict) and use CSS for all styling/presentation, 
JF> which means your pages will accessible via the largest possible number 
JF> of viewing devices, like PDA, WAP, text-to-speech, desktop browsers, 
JF> Web TV, etc.

JF> The move away from table based layouts and poorly accessible webpages 
JF> is a big one, but not THAT big :)


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


From my experience css is even more unreliable than user agent being set and all
browser producers seem to have their own idea of what a standard is supposed to
look like as well. At least with table layouts most of the current desktop
browsers will make a half decent try. With companies like Netscape and Microsoft
providing browsers you should stay away from strict anything is my advice :)
The ideal way of detecting a wap browser is through the accepted mime types from
the request header but I am not sure if that info is passed on by PHP.

You could try

<?
$headers = apache_request_headers();
print_r($headers);
<?
and see what is supplied under accept with various devices

You need to look for something like this:

text/vnd.wap.wml for .wml files (WML source files)
application/vnd.wap.wmlc for .wmlc files (WML compiled files)
text/vnd.wap.wmlscript for .wmls files (WMLScript source files)
application/vnd.wap.wmlscriptc for .wmlsc files (WMLScript compiled files)
image/vnd.wap.wbmp for .wbmp files (wireless bitmaps) 

-- 
regards,
Tom

--- End Message ---
--- Begin Message --- On Sunday, October 12, 2003, at 07:46 PM, Tom Rogers wrote:

From my experience css is even more unreliable than user agent being set and all
browser producers seem to have their own idea of what a standard is supposed to
look like as well. At least with table layouts most of the current desktop
browsers will make a half decent try. With companies like Netscape and Microsoft
providing browsers you should stay away from strict anything is my advice :)

It depends what you're aiming for. If you're aiming for pixel perfect display on the usual browsers, great -- go for tables and the usual hacks. But in the meantime you're sacrificing forwards compatibility for backwards compatibility, making your site hugely inaccessible, causing huge ongoing development costs (update the hacks to support newer browsers and devices), etc etc.


What's the point in developing three or more sites (WAP, PDA, Desktop) when one can do the same, with a few SMALL sacrifices.

As a bonus, you're developing HTML for EVERYONE, not turning away ANYONE, and you're saving your client some money.


Anyway, this is getting a little OT :) You're entitled to do things your way, and so am I... the $'s and accessibility are making my decisions for me.




The ideal way of detecting a wap browser is through the accepted mime types from
the request header but I am not sure if that info is passed on by PHP.


You could try

<?
$headers = width: 300px;;
print_r($headers);
<?
and see what is supplied under accept with various devices

You need to look for something like this:

text/vnd.wap.wml for .wml files (WML source files)
application/vnd.wap.wmlc for .wmlc files (WML compiled files)
text/vnd.wap.wmlscript for .wmls files (WMLScript source files)
application/vnd.wap.wmlscriptc for .wmlsc files (WMLScript compiled files)
image/vnd.wap.wbmp for .wbmp files (wireless bitmaps)



Nice idea!


Justin
--- End Message ---
--- Begin Message --- Hi Justin et al,

Yes you are right that user agent field is not always reliable but 98% of the time you will be able to tell if it's a mobile or a pc. That's good enough. If someone fakes the header they will just get a wrong content type and no harm done. I first did a wap site with php using this method way back in 2000. Unidentified browsers were given html.

As for a detailed list of various mobile browers, it's impossible to maintain this list. That's why there is a sourceforge project that does it and we can all benefit.

did i mention xslt?



Justin French wrote:

On Sunday, October 12, 2003, at 12:02 PM, Manuel Vázquez Acosta wrote:

Take a look at what is printed by:

var_dump($_SERVER);

Maybe the HTTP_USER_AGENT can lead you to somewhere out of this problem.

Manu.

"Shaun" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]

Hi,

I have created an online system, and have created a WAP version, and am
currently crreating a PDA version. What I wuold like to to do is give out
the same URL instead of domain.com for normal use, domain.com/wap/ or
domain.com/pda/. Is there a way of detecting what device is loading the

site


and redirect them accordingly?

Thanks for your help



Manuel, Shaun,

$_SERVER['HTTP_USER_AGENT'] (just like anything else from the client side) can't be trusted to either exist, or to be correct. Some user agents don't set this value, and it's quite easy for it to be faked. More to the point, there's no way you can possibly account for all possible user agents out there... perhaps only the popular ones.

So, $_SERVER['HTTP_USER_AGENT'] is a good starting point or method for guessing where to send people, but it's not fail safe AT ALL.


I think the fail safe way is to create pages which are standards compliant (XHTML strict) and use CSS for all styling/presentation, which means your pages will accessible via the largest possible number of viewing devices, like PDA, WAP, text-to-speech, desktop browsers, Web TV, etc.


The move away from table based layouts and poorly accessible webpages is a big one, but not THAT big :)


Justin



-- Raditha Dissanayake. ------------------------------------------------------------------------ http://www.radinks.com/sftp/ | http://www.raditha/megaupload/ Lean and mean Secure FTP applet with | Mega Upload - PHP file uploader Graphical User Inteface. Just 150 KB | with progress bar.

--- End Message ---
--- Begin Message ---
Greetings,

This is the example from the php manual:

***************************************
Example 6. sprintf(): formatting currency

<?php
$money1 = 68.75;
$money2 = 54.35;
$money = $money1 + $money2;
// echo $money will output "123.1";
$formatted = sprintf("%01.2f", $money);        // my question comes here
// echo $formatted will output "123.10"
?>
***************************************

I don't understand the meaning of the 01 above, which follows the % sign. I
tried the "%.2f" and "%1.2f", both work fine. So, what's the meaning of
01(especially what the 0 is for)? Seems very much the same as C anyway :-).

Please explain.

--- End Message ---
--- Begin Message ---
On Sun, Oct 12, 2003 at 06:09:21PM +1000, Wang Feng wrote:
: 
: This is the example from the php manual:
[...]
: $formatted = sprintf("%01.2f", $money);        // my question comes here
: // echo $formatted will output "123.10"
[...]
: 
: I don't understand the meaning of the 01 above, which follows the % sign. I
: tried the "%.2f" and "%1.2f", both work fine. So, what's the meaning of
: 01(especially what the 0 is for)? Seems very much the same as C anyway :-).

The "01" part guarantees that your money always has a preceding "0" for
decimal-only amounts.  For example, ".15" should be displayed as "0.15".

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

If I get rid of the 0 and tried this:

$price=.65;
$f_price=sprintf("%1.2f",$price);

It displays "0.65" in my Mozilla browser correctly. What do you say then?

BTW, what's the 1 used for?

cheers,

feng


----- Original Message -----
From: "Eugene Lee" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, October 12, 2003 6:49 PM
Subject: Re: [PHP] newbie question


> On Sun, Oct 12, 2003 at 06:09:21PM +1000, Wang Feng wrote:
> :
> : This is the example from the php manual:
> [...]
> : $formatted = sprintf("%01.2f", $money);        // my question comes here
> : // echo $formatted will output "123.10"
> [...]
> :
> : I don't understand the meaning of the 01 above, which follows the %
sign. I
> : tried the "%.2f" and "%1.2f", both work fine. So, what's the meaning of
> : 01(especially what the 0 is for)? Seems very much the same as C anyway
:-).
>
> The "01" part guarantees that your money always has a preceding "0" for
> decimal-only amounts.  For example, ".15" should be displayed as "0.15".
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

--- End Message ---
--- Begin Message ---
On Sun, Oct 12, 2003 at 06:57:35PM +1000, Wang Feng wrote:
: 
: If I get rid of the 0 and tried this:
: 
: $price=.65;
: $f_price=sprintf("%1.2f",$price);
: 
: It displays "0.65" in my Mozilla browser correctly. What do you say then?

I say, "I dunno".  :-)  It seems to follow C's printf(3) conversion
specification.  If a decimal point is needed for a float, it must also
have a digit in front of the decimal point.  This is kind of annoying if
I want to print decimal-only values without preceding zeroes.  Maybe
money_format() is a better solution.

: BTW, what's the 1 used for?

Specifies the minimum character width of the conversion.  See PHP's
sprintf() docs for more details.


--- End Message ---
--- Begin Message ---
* Thus wrote Eugene Lee ([EMAIL PROTECTED]):
> On Sun, Oct 12, 2003 at 06:57:35PM +1000, Wang Feng wrote:
> : 
> : If I get rid of the 0 and tried this:
> : 
> : $price=.65;
> : $f_price=sprintf("%1.2f",$price);
> : 
> : It displays "0.65" in my Mozilla browser correctly. What do you say then?
> 
> I say, "I dunno".  :-)  It seems to follow C's printf(3) conversion
> specification.  If a decimal point is needed for a float, it must also
> have a digit in front of the decimal point.  This is kind of annoying if
> I want to print decimal-only values without preceding zeroes.  Maybe
> money_format() is a better solution.

yep, and even  "%0.2f" yields 0.65


Curt
-- 
"My PHP key is worn out"

  PHP List stats since 1997: 
          http://zirzow.dyndns.org/html/mlists/

--- End Message ---
--- Begin Message ---
I think, without any help, the only way to make it clear is to read the
source code of that function in php. The manual doesn't explain the function
well.

But I'm sure many people here knows the answer well. Come on. Where are you?


cheers,

feng



----- Original Message -----
From: "Curt Zirzow" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, October 13, 2003 2:01 AM
Subject: Re: [PHP] newbie question


> * Thus wrote Eugene Lee ([EMAIL PROTECTED]):
> > On Sun, Oct 12, 2003 at 06:57:35PM +1000, Wang Feng wrote:
> > :
> > : If I get rid of the 0 and tried this:
> > :
> > : $price=.65;
> > : $f_price=sprintf("%1.2f",$price);
> > :
> > : It displays "0.65" in my Mozilla browser correctly. What do you say
then?
> >
> > I say, "I dunno".  :-)  It seems to follow C's printf(3) conversion
> > specification.  If a decimal point is needed for a float, it must also
> > have a digit in front of the decimal point.  This is kind of annoying if
> > I want to print decimal-only values without preceding zeroes.  Maybe
> > money_format() is a better solution.
>
> yep, and even  "%0.2f" yields 0.65
>
>
> Curt
> --
> "My PHP key is worn out"
>
>   PHP List stats since 1997:
>   http://zirzow.dyndns.org/html/mlists/
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

--- End Message ---
--- Begin Message ---
On Sun, 2003-10-12 at 12:19, Wang Feng wrote:
> I think, without any help, the only way to make it clear is to read the
> source code of that function in php. The manual doesn't explain the function
> well.
> 
> But I'm sure many people here knows the answer well. Come on. Where are you?

I believe the documentation (in at least on of the ?printf() functions
describes how the implementation follows the C specs. I'm pretty sure
the ?printf() family of functions were added almost entirely for the
benefit of C coders :)

Cheers,
Rob.

> 
> 
> cheers,
> 
> feng
> 
> 
> 
> ----- Original Message -----
> From: "Curt Zirzow" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Monday, October 13, 2003 2:01 AM
> Subject: Re: [PHP] newbie question
> 
> 
> > * Thus wrote Eugene Lee ([EMAIL PROTECTED]):
> > > On Sun, Oct 12, 2003 at 06:57:35PM +1000, Wang Feng wrote:
> > > :
> > > : If I get rid of the 0 and tried this:
> > > :
> > > : $price=.65;
> > > : $f_price=sprintf("%1.2f",$price);
> > > :
> > > : It displays "0.65" in my Mozilla browser correctly. What do you say
> then?
> > >
> > > I say, "I dunno".  :-)  It seems to follow C's printf(3) conversion
> > > specification.  If a decimal point is needed for a float, it must also
> > > have a digit in front of the decimal point.  This is kind of annoying if
> > > I want to print decimal-only values without preceding zeroes.  Maybe
> > > money_format() is a better solution.
> >
> > yep, and even  "%0.2f" yields 0.65
> >
> >
> > Curt
> > --
> > "My PHP key is worn out"
> >
> >   PHP List stats since 1997:
> >   http://zirzow.dyndns.org/html/mlists/
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
-- 
.------------------------------------------------------------.
| 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 ---
 "1. An optional padding specifier that says what character will be used for
padding the results to the right string size. This may be a space character
or a 0 (zero character). The default is to pad with spaces. An alternate
padding character can be specified by prefixing it with a single quote (').
See the examples below."
"3. An optional number, a width specifier that says how many characters
(minimum) this conversion should result in."
---- http://au.php.net/manual/en/function.sprintf.php



Assume that $price=.65; then the "%0.2f" yields 0.65.

If we follow what the manual says, then can you tell me what the 0 is used
for? Is it a (optional) paddinng spcifier OR is it a (optional) width
specifier OR both? And why does it yiled 0.65 rather than .65?


(The manual doesn't explain things clear, man.)


cheers,

feng


----- Original Message -----
From: "Robert Cummings" <[EMAIL PROTECTED]>
To: "Wang Feng" <[EMAIL PROTECTED]>
Cc: "Curt Zirzow" <[EMAIL PROTECTED]>; "PHP-General"
<[EMAIL PROTECTED]>
Sent: Monday, October 13, 2003 2:29 AM
Subject: Re: [PHP] newbie question

> I believe the documentation (in at least on of the ?printf() functions
> describes how the implementation follows the C specs. I'm pretty sure
> the ?printf() family of functions were added almost entirely for the
> benefit of C coders :)
>
> Cheers,
> Rob.
>
> >
> >
> > cheers,
> >
> > feng
> >
> >
> >
> > ----- Original Message -----
> > From: "Curt Zirzow" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Monday, October 13, 2003 2:01 AM
> > Subject: Re: [PHP] newbie question
> >
> >
> > > * Thus wrote Eugene Lee ([EMAIL PROTECTED]):
> > > > On Sun, Oct 12, 2003 at 06:57:35PM +1000, Wang Feng wrote:
> > > > :
> > > > : If I get rid of the 0 and tried this:
> > > > :
> > > > : $price=.65;
> > > > : $f_price=sprintf("%1.2f",$price);
> > > > :
> > > > : It displays "0.65" in my Mozilla browser correctly. What do you sa
y
> > then?
> > > >
> > > > I say, "I dunno".  :-)  It seems to follow C's printf(3) conversion
> > > > specification.  If a decimal point is needed for a float, it must
also
> > > > have a digit in front of the decimal point.  This is kind of
annoying if
> > > > I want to print decimal-only values without preceding zeroes.  Maybe
> > > > money_format() is a better solution.
> > >
> > > yep, and even  "%0.2f" yields 0.65
> > >
> > >
> > > Curt
> > > --
> > > "My PHP key is worn out"
> > >
> > >   PHP List stats since 1997:
> > >   http://zirzow.dyndns.org/html/mlists/
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> --
> .------------------------------------------------------------.
> | 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.          |
> `------------------------------------------------------------'
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

--- End Message ---
--- Begin Message ---
On Sun, Oct 12, 2003 at 02:09:38AM +0200, DvDmanDT wrote:
: 
: Does anyone have a good solution on how to get the age of someone from a
: date column in mysql... This is what I have, but it's not really the
: truth... What's the right way to do it?
: 
: floor((time()-$a["born"])/(3600*24*365.25))
: 
: where $a["born"] is the timestamp of the birthdate... Current query:

This should work for well-formed timestamps, i.e. they are not in the
future:

function age($ts)
{
    list($y1, $m1, $d1) = explode(' ', date('Y m d', $ts));
    list($y2, $m2, $d2) = explode(' ', date('Y m d', time()));
    $age = $y2 - $y1 - ((($m2 < $m1) || ($d2 < $d1)) ? 1 : 0);
    return $age;
}

--- End Message ---
--- Begin Message ---
* Thus wrote Eugene Lee ([EMAIL PROTECTED]):
> On Sun, Oct 12, 2003 at 02:09:38AM +0200, DvDmanDT wrote:
> : 
> : Does anyone have a good solution on how to get the age of someone from a
> : date column in mysql... This is what I have, but it's not really the
> : truth... What's the right way to do it?
> : 
> : floor((time()-$a["born"])/(3600*24*365.25))
> : 
> : where $a["born"] is the timestamp of the birthdate... Current query:
> 
> This should work for well-formed timestamps, i.e. they are not in the
> future:
> 
> function age($ts)
> {
>     list($y1, $m1, $d1) = explode(' ', date('Y m d', $ts));
>     list($y2, $m2, $d2) = explode(' ', date('Y m d', time()));
>     $age = $y2 - $y1 - ((($m2 < $m1) || ($d2 < $d1)) ? 1 : 0);

What happens if the month is the same but the day hasnt been
reached?


Shouldnt this be:
     $age = $y2 - $y1 - ((($m2 < $m1) || ($m2 == $m1 && $d2 < $d1)) ? 1 : 0);

To account for it being the same month but not yet the day.


Curt
-- 
"My PHP key is worn out"

  PHP List stats since 1997: 
          http://zirzow.dyndns.org/html/mlists/

--- End Message ---
--- Begin Message ---
I have found that this script doesn't work:

read_tag.php

---
<?php

function readTag($filename, $tagtype, $debug = 0) {
$filedata = file_get_contents($filename);
$tagrealname = "<bttag=";
$tagrealname .= $tagtype;
$tagrealname .= ">";

$tagdata = stristr($filedata, $tagrealname);
$posofend = strpos($tagdata, "</bttag>");
$length = strlen($tagdata);
$lengthoftag = strlen($tagrealname);
$lengthofend = strlen("</bttag>");
$lengthofstr = $length - $posofend - $lengthoftag;
$returndata = substr($tagdata, $lengthoftag, $lengthofstr);
if ($debug == 1) {
echo "<br>Length = " . $length;
echo "<br>Of Tag = " . $lengthoftag;
echo "<br>Of Str = " . $lengthofstr;
echo "<br>Of End = " . $posofend;
echo "<br>TagData:<br>" . $tagdata;
}
return $returndata;
}
?>

<HTML>
<BODY>
<h1>Test readTag-functie</h1>
<?php echo readTag("test.tag", "bassie", 1); ?>
</body>
</html>

---
And with this, it needs the file 'test.tag'
---
<bttag=bassie>
I am myself!!
</bttag>
<bttag=test>
This is a test!!!
</bttag>
<bttag=welcome>
Welcome!!!
</bttag>
<bttag=close>
Closing!!!
</bttag>
---
The first parameter of the readTag function is the filename of the tag file.
The second is the tag to search for an the third is the debug mode.

The error is that if i load this, the readTag function returns everything
except for the Closing!!!

What's wrong?

I'm running Win XP with Apache 2.0.44(Win32) CGI setup and PHP 4.3.3

--- End Message ---
--- Begin Message ---
Try this:

function readTag($filenane, $tagtype, $degub = false)
// I prefer boolean for debug :)
{
    $filedata = file_get_contents($filename);
    $tagtype = preg_quote($tagtype);
    $tagRegExp = "/<battag=$tagtype\s*>((?:.|\s)*?)</battag\s*>/";
    preg_replace_callback($tagRegExp, 'replaceFunc', $filedata);
}

function replaceFunc(match)
{
    // match[0] ---  the whole tag from <x> to </x>
    // match[1] ---  the contents of the tag
    //                I am my self !!! in the example


    return WHATEVER_YOU_WANT_TO_REPLACE_THE_TAG;
}

I didnt make sure this script will work 100%; but it should.

Manu.

"Bas" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I have found that this script doesn't work:
>
> read_tag.php
>
> ---
> <?php
>
> function readTag($filename, $tagtype, $debug = 0) {
> $filedata = file_get_contents($filename);
> $tagrealname = "<bttag=";
> $tagrealname .= $tagtype;
> $tagrealname .= ">";
>
> $tagdata = stristr($filedata, $tagrealname);
> $posofend = strpos($tagdata, "</bttag>");
> $length = strlen($tagdata);
> $lengthoftag = strlen($tagrealname);
> $lengthofend = strlen("</bttag>");
> $lengthofstr = $length - $posofend - $lengthoftag;
> $returndata = substr($tagdata, $lengthoftag, $lengthofstr);
> if ($debug == 1) {
> echo "<br>Length = " . $length;
> echo "<br>Of Tag = " . $lengthoftag;
> echo "<br>Of Str = " . $lengthofstr;
> echo "<br>Of End = " . $posofend;
> echo "<br>TagData:<br>" . $tagdata;
> }
> return $returndata;
> }
> ?>
>
> <HTML>
> <BODY>
> <h1>Test readTag-functie</h1>
> <?php echo readTag("test.tag", "bassie", 1); ?>
> </body>
> </html>
>
> ---
> And with this, it needs the file 'test.tag'
> ---
> <bttag=bassie>
> I am myself!!
> </bttag>
> <bttag=test>
> This is a test!!!
> </bttag>
> <bttag=welcome>
> Welcome!!!
> </bttag>
> <bttag=close>
> Closing!!!
> </bttag>
> ---
> The first parameter of the readTag function is the filename of the tag
file.
> The second is the tag to search for an the third is the debug mode.
>
> The error is that if i load this, the readTag function returns everything
> except for the Closing!!!
>
> What's wrong?
>
> I'm running Win XP with Apache 2.0.44(Win32) CGI setup and PHP 4.3.3

--- End Message ---
--- Begin Message ---
* Thus wrote Bas ([EMAIL PROTECTED]):
> 
> ---
> And with this, it needs the file 'test.tag'
> ---
> <bttag=bassie>
> I am myself!!
> </bttag>
[...]
> 
> The error is that if i load this, the readTag function returns everything
> except for the Closing!!!

Do you mean that all the other tags return the proper content
except the last one?  I didn't study the code too closely for
reasons that follow.

> 
> What's wrong?

Glad you asked :)   Here are a couple things I noticed:
  - every call to this function has the overhead of reading the
    file.
  - The parsing is error prone, ie. someone puts: <bttag=bassie >

If its possible I would take a complete different approach at
parsing the tags.  There are two options that I see right away. Use
XML as your data format and an xml parser to obtain the values in
the tags.  Or use preg_match_all.  Here is how I would approach the
preg_match_all:

function parseTags($file) {
  /* readfile... here */

  $tag_match = "!<bttag=(\w*)>\s*([^<]*)\s*</bttag>!is";
  preg_match_all($tag_match, $filedata, $matches);
  for ($i=0; $i< count($matches[0]); $i++) {
    $tagname = $matches[1][$i];
    $tags[$tagname] = $matches[2][$i];
  }
  return $tags;
}

Then you can use it like so:

<?php
$bttags = parseTags('test.tag');
?>
<HTML>
<BODY>
<h1>Test readTag-functie</h1>
<?php echo $bttags['bassie']; ?>
</body>
</html>


HTH,

Curt
-- 
"My PHP key is worn out"

  PHP List stats since 1997: 
          http://zirzow.dyndns.org/html/mlists/

--- End Message ---
--- Begin Message ---
Hi,
Is there a way to determite with PHP thath site visitor is in https (SSL)
mode or in normal mode ?

Thanks,
Rosen

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

Sunday, October 12, 2003, 9:09:15 PM, you wrote:
R> Hi,
R> Is there a way to determite with PHP thath site visitor is in https (SSL)
R> mode or in normal mode ?

R> Thanks,
R> Rosen


put phpinfo(32); at the top of the page and that should show what is available
with an ssl connection if you make one.

-- 
regards,
Tom

--- End Message ---
--- Begin Message ---
I.e. if  I use _SERVER["SERVER_PORT"] = 443  - for https connection and 80
for "normal" - i'll be able to determite if user is in https mode - I think
thath should be works . ?

Thanks,
Rosen





 "Tom Rogers" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi,
>
> Sunday, October 12, 2003, 9:09:15 PM, you wrote:
> R> Hi,
> R> Is there a way to determite with PHP thath site visitor is in https
(SSL)
> R> mode or in normal mode ?
>
> R> Thanks,
> R> Rosen
>
>
> put phpinfo(32); at the top of the page and that should show what is
available
> with an ssl connection if you make one.
>
> --
> regards,
> Tom

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

Sunday, October 12, 2003, 9:24:40 PM, you wrote:
R> I.e. if  I use _SERVER["SERVER_PORT"] = 443  - for https connection and 80
R> for "normal" - i'll be able to determite if user is in https mode - I think
R> thath should be works . ?

R> Thanks,
R> Rosen



looks like a good start :)

-- 
regards,
Tom

--- End Message ---
--- Begin Message ---
On Sun, Oct 12, 2003 at 01:09:15PM +0200, Rosen wrote:
: 
: Is there a way to determite with PHP thath site visitor is in https (SSL)
: mode or in normal mode ?

Check for the existence of $_SERVER['HTTPS'] which gets set only on SSL
pages.  I wonder why it's still not mentioned in the official docs.

--- End Message ---
--- Begin Message ---
On Sun, Oct 12, 2003 at 01:24:40PM +0200, Rosen wrote:
: 
: I.e. if  I use _SERVER["SERVER_PORT"] = 443  - for https connection and 80
: for "normal" - i'll be able to determite if user is in https mode - I think
: thath should be works . ?

Technically, you can't guarantee that anything running over port 443
will be HTTPS.  This is part of the more general problem of running your
web server on non-standard ports.

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

Sunday, October 12, 2003, 8:46:41 PM, you wrote:
EL> On Sun, Oct 12, 2003 at 01:24:40PM +0200, Rosen wrote:
EL> : 
EL> : I.e. if  I use _SERVER["SERVER_PORT"] = 443  - for https connection and 80
EL> : for "normal" - i'll be able to determite if user is in https mode - I think
EL> : thath should be works . ?

EL> Technically, you can't guarantee that anything running over port 443
EL> will be HTTPS.  This is part of the more general problem of running your
EL> web server on non-standard ports.


His script will only see valid ssl connections as all other attempts should be
ditched by apache or whatever before php gets involved...in theory anyway :)

-- 
regards,
Tom

--- End Message ---
--- Begin Message ---
On Sun, Oct 12, 2003 at 08:52:30PM +1000, Tom Rogers wrote:
: Sunday, October 12, 2003, 8:46:41 PM, Eugene wrote:
: EL> On Sun, Oct 12, 2003 at 01:24:40PM +0200, Rosen wrote:
: EL> : 
: EL> : I.e. if  I use _SERVER["SERVER_PORT"] = 443  - for https connection
: EL> : and 80 for "normal" - i'll be able to determite if user is in https
: EL> : mode - I think thath should be works . ?
: 
: EL> Technically, you can't guarantee that anything running over port 443
: EL> will be HTTPS.  This is part of the more general problem of running your
: EL> web server on non-standard ports.
: 
: His script will only see valid ssl connections as all other attempts should be
: ditched by apache or whatever before php gets involved...in theory anyway :)

Unless Apache is configured so that both SSL and non-SSL virtualhosts
to point to the same directory containing said script, or said script is
shared (via PHP include(), require(), etc.) by other PHP scripts in both
SSL and non-SSL virtualhosts.  :-)

And $_SERVER['HTTPS'] is so much easier to check for existence!

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

Sunday, October 12, 2003, 10:27:21 PM, you wrote:

EL> Unless Apache is configured so that both SSL and non-SSL virtualhosts
EL> to point to the same directory containing said script, or said script is
EL> shared (via PHP include(), require(), etc.) by other PHP scripts in both
EL> SSL and non-SSL virtualhosts.  :-)

EL> And $_SERVER['HTTPS'] is so much easier to check for existence!

I couldn't remember what variables were set so I said to use phpinfo and see
what pops up....you are probably right :)

-- 
regards,
Tom

--- End Message ---
--- Begin Message ---
* Thus wrote Rosen ([EMAIL PROTECTED]):
> I.e. if  I use _SERVER["SERVER_PORT"] = 443  - for https connection and 80
> for "normal" - i'll be able to determite if user is in https mode - I think
> thath should be works . ?

There is no guarantee that port 443 == https and 80 == http.

Curt
-- 
"My PHP key is worn out"

  PHP List stats since 1997: 
          http://zirzow.dyndns.org/html/mlists/

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

Does the new xml api provide high level function calls (does it map the
libxml api)?

Regards

Dennis Heuer

--- End Message ---
--- Begin Message ---
Not to sure about what I'm saying, but if I remember well my readings
regarding php5 and xml, I think it implements the gnome libxml2, not libxml,
which is much better.
Hopefully php + xml will be less of a pain in the arse after the 5 is out.

cheers

.b

-----Original Message-----
From: Dennis Heuer [mailto:[EMAIL PROTECTED]
Sent: 12 October 2003 15:19
To: [EMAIL PROTECTED]
Subject: [PHP] xml in php5.0.0beta1


Hello -

Does the new xml api provide high level function calls (does it map the
libxml api)?

Regards

Dennis Heuer

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

--- End Message ---
--- Begin Message ---
<[EMAIL PROTECTED]>
John Ryan:
> Loser

>>And believe it or
>> not, the shift key is there for a reason.
Please don't flame.

--- End Message ---
--- Begin Message ---
I'm one of the ignorant multitude beginning to grope their way across the threshhold 
of web programming. I come from another world, not computer science, and thus have a 
question so basic I haven't found any reference to it anywhere. It's killing me.

In the php statement
$q->qzml();
what is the symbol '->' called? What does it mean?

A php script with this line in it, in which $q is an object and qzml() is a function, 
returns the error message "undefined function". When I remove this line, the function 
qzml() is recognized.

I have also come across the symbol '=>'. I assume it is not the same symbol. What is 
it, and what does it mean?

Any help would be greatly appreciated.

Thanks,
-Paul

--- End Message ---
--- Begin Message --- Paul Freedman wrote:
I'm one of the ignorant multitude beginning to grope their way across the threshhold of web programming. I come from another world, not computer science, and thus have a question so basic I haven't found any reference to it anywhere. It's killing me.

In the php statement
$q->qzml();
what is the symbol '->' called? What does it mean?
It calls *member* function of object $q. So even if qzml is a global function it will not work, the function must be defined in the object's class definition:

class Q {

        function qzml() {
                echo 'Q::qzml() function<br>';
        }       
}

$q=new Q;

$q->qzml();


A php script with this line in it, in which $q is an object and qzml() is a function, returns the error message "undefined function". When I remove this line, the function qzml() is recognized.


I have also come across the symbol '=>'. I assume it is not the same symbol. What is it, and what does it mean?

It is used to assign values to keys in array() construct: http://sk.php.net/manual/en/function.array.php


Any help would be greatly appreciated.


Thanks,
-Paul

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

I am trying to add a function to my template system where the script 
will output a similar name to the one entered, e.g.:
array('main','page1','testing','main_info');
user input: 'mai'
then it should return 'main' & 'main_info' from the array as possible 
matches. (Ok, easy example, but it's supposed to work as well with 
worse typos)

Anyway, so I stumbled upon the levenshtein funtion which seems to be 
the right thing to use for s.th. like that.

However, how does on php.net the "search function" do it? Does it use 
a database match checking, or are they using some php function(s) to 
display matching function names?

Thanks,
Duncan

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

I am currently working with the output control functions and they work
like a charm - as long as I don't start using IE to view my test page.

I put together the below code from a couple of comments on php.net and
it works like a charm with mozilla, where the content gets displayed
with each loop run - but as soon as I start using tables then IE waits
until the table gets closed to display the output, so it basically
waits until everything is put together anyway and outputs it all.

So, mozilla starts drawing the first table which gets surrounded by
the first table border, then the next table appears so that both get
surrounded by the first table border and so on.
IE simply keeps on loading until all 3 parts of the array have been
put together and then starts displaying the output in the window.

So, my question: is there a way to make IE display the flush'ed output
even when I am using tables?
I guess I am simply making a stupid mistake here, but so far all my
tries resulted in IE not being able to use flush() within tables
(e.g.: remove the surrounding table and it will work just fine again).

S.o. mentioned in the php.net comments that the < tr > tag is causing
those problems, but I tried all kind of combinations to no avail.

However, since I see that kind of output control on several sites I assume there has 
to be some kind of way to get the data displayed before the table structure has been 
closed again - or is that an ASP only feature?

Any help would be appreciated,

Duncan

<?php
$arg[0] = '<table border=1><tr><td><table><tr><td>Line
1</td></tr></table></td></tr>';
$arg[1] = '<tr><td><table><tr><td>Line 2</td></tr></table></td></tr>';
$arg[2] = '<tr><td><table><tr><td>Line
3</td></tr></table></td></tr></table>';

        ob_start();
        for ($j=0; $j != sizeof($arg); $j++)
        {

                @eval("?>" . $arg[$j] .str_pad(" ", 300). "<?php ");
                ob_get_contents();
                ob_flush();
                flush();
                sleep(5);
        }

        ob_end_clean();
?>


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

is there a way to create a mail (with the mail() function) that contains php in the message.

Like:

<?php
$to  = "[EMAIL PROTECTED]";
$subject = "a subject";
$message = ????

I WANT TO PUT SOME PHP IN HERE TO CREATE A TABLE IN THE MESSAGE:

$columnbooks = mysql_list_fields($dbname,tmp,$mysql_link);
$sqlbooks = "select isbn,books.title, writer, publisher from tmp,books where tmp.user=books.user";
$resultbooks = mysql_db_query($dbname,$sqlbooks);
?>
<table cellpadding="2" cellspacing="2" border="1" style="text-align: left; width: 100%;">
<?php
while ($valuebooks = mysql_fetch_array($resultbooks))
{ print "<tr bgcolor=#ccf504>";
for($i=0; $i< 4; $i++ )
{
$gebruikerbooks=$valuebooks[$i];
print "<td> $gebruikerbooks </td>";
}
print "</tr>";
}
mysql_free_result($resultbooks);


THIS SHOULD BE THE END OF THE MESSAGE


HERE I WILL DO THE MAILING


mail($to,$subject,$message);
?>

--- End Message ---
--- Begin Message ---
Hallo Onno,

am Sonntag, 12. Oktober 2003 um 20:07 hast Du Folgendes gekritzelt:

OK> Hi,

OK> is there a way to create a mail (with the mail() function) that contains 
OK>   php in the message.

OK> Like:

OK> <?php
OK> $to  = "[EMAIL PROTECTED]";
OK> $subject = "a subject";
OK> $message = ????

OK> I WANT TO PUT SOME PHP IN HERE TO CREATE A TABLE IN THE MESSAGE:

OK> $columnbooks = mysql_list_fields($dbname,tmp,$mysql_link);
OK> $sqlbooks = "select isbn,books.title, writer, publisher from tmp,books 
OK> where tmp.user=books.user";
OK> $resultbooks = mysql_db_query($dbname,$sqlbooks);
?>>
OK> <table cellpadding="2" cellspacing="2" border="1" style="text-align: 
left; width: 100%;">>
OK> <?php
OK> while   ($valuebooks = mysql_fetch_array($resultbooks))
OK> {       print "<tr bgcolor=#ccf504>";
OK>          for($i=0; $i< 4; $i++ )
OK>          {
OK>          $gebruikerbooks=$valuebooks[$i];
OK>          print "<td> $gebruikerbooks </td>";
OK>          }
OK>          print "</tr>";
OK> }
OK> mysql_free_result($resultbooks);

OK> THIS SHOULD BE THE END OF THE MESSAGE
 

OK> HERE I WILL DO THE MAILING

OK> mail($to,$subject,$message);
?>>


You should know that php runs on a server, not on the client machine. So what do you 
want to
do with php-code in a mail? You could put html (generated by php for
example), so that the mail-reader can display a table.


SvT


-- 
Who is the ennemy?

mailto:[EMAIL PROTECTED]

--- End Message ---
--- Begin Message ---
Hi,
I have a problem with destroing a session.
I have made a login page and the login work ok.
I register the things i want like that:
<?
session_register(uid); $uid= mysql_result($result,0,'userid');
session_register(pwd); $pwd= mysql_result($result,0,'password');
session_register(name); $name= mysql_result($result,0,'name');
session_register(memberid); $memberid= mysql_result($result,0,'id');
?>

I try to make the logout page like that:

<?php

session_start();
session_unset();
session_destroy();
?>

but it dont work.
I have
a.. PHP - 4.0.5
a.. MySQL - 3.23.32
a.. Apache - 1.3.14
a.. PHPMyAdmin - 2.1.0
a.. Perl - nsPerl 5.005_03

session.auto_start Off
session.cache_expire 180
session.cache_limiter nocache
session.cookie_domain no value
session.cookie_lifetime 0
session.cookie_path /
session.entropy_file no value
session.entropy_length 0
session.gc_maxlifetime 1440
session.gc_probability 1
session.name PHPSESSID
session.referer_check no value
session.save_handler files
session.save_path c:/php4/sessions
session.serialize_handler php
session.use_cookies On

installed apache on win2000

The session is not destroyd. Session_unset dont work to.
Can someone help me?
thanks.


--- End Message ---

Reply via email to