Re: [PHP] Merging Strings

2005-05-03 Thread Jochem Maas
Rolf van de Krol wrote:
Hi all,
why do result the following two examples in two different value for $month?
(1)
$current_date = getdate(time());
$month= strval($current_date['year']);
$month   .= (strlen(strval($current_date['mon'])) == 2)
  ? $current_date['mon']
  : ("0".$current_date['mon']);
$current_date = getdate(time());
$month= strval($current_date['year']) . (strlen(strval($current_date['mon'])) == 2)  ? 
$current_date['mon']
  : ("0".$current_date['mon']);

in the second version:
strval($current_date['year']) . (strlen(strval($current_date['mon'])) == 2)
is equal to TRUE, therefore $current_date['mon'] is returned, you are missing
parentheses around the tertiary expression (?:) so:
$current_date = getdate(time());
$month= strval($current_date['year']) .
  ((strlen(strval($current_date['mon'])) == 2) ? $current_date['mon'] : 
"0".$current_date['mon']);

btw, have a look at str_pad:
$current_date = getdate();
$month= str_pad($current_date['mon'], 2, "0", STR_PAD_LEFT);
echo $month;
The first example sets $month to 200505 and the second sets it to 5. Why is
that. In my opinion they both should set it to 200505.
Is this a weird bug, or did i something wrong?
I'm using PHP 4.3.10 with Apache 1.3.33 on W2K Pro, but the server of my
hosting provider does the same (php 4.3.10 + apache (don't know the version,
i guess 1.3.33) on linux (i'm not sure, but i thought it was redhat)).
Rolf van de Krol
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Merging Strings

2005-05-03 Thread Rolf van de Krol
Hi all,

why do result the following two examples in two different value for $month?
(1)
$current_date = getdate(time());
$month = strval($current_date['year']);
$month .= (strlen(strval($current_date['mon'])) ==
2)?$current_date['mon']:("0".$current_date['mon']);
(2)
$current_date = getdate(time());
$month = strval($current_date['year']) .
(strlen(strval($current_date['mon'])) ==
2)?$current_date['mon']:("0".$current_date['mon']);

The first example sets $month to 200505 and the second sets it to 5. Why is
that. In my opinion they both should set it to 200505.
Is this a weird bug, or did i something wrong?

I'm using PHP 4.3.10 with Apache 1.3.33 on W2K Pro, but the server of my
hosting provider does the same (php 4.3.10 + apache (don't know the version,
i guess 1.3.33) on linux (i'm not sure, but i thought it was redhat)).

Rolf van de Krol

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



Re: [PHP] is this possible in PHP?

2005-05-03 Thread Rasmus Lerdorf
Dasmeet Singh wrote:
Hi!
I want a script that can display a list of all the websites currently 
hosted on my server.. (i have root access to the server)

Say I have a page sitesonmyserver.php..it shud show a list of all the 
websites hosted on my server..eg:
abc.com
xyz.om

And any additional info if possible?
Is such a thing possible in PHP.. or does any such script exists?
Generally, no.  You would need some black magic that probed the guts of 
your web server for this information.  And by black magic I mean some 
low-level C code.

A bit of grey magic I wrote almost exactly 9 years ago now! (May 1, 
1996) in the form of Apache's mod_info module might help you out a 
little bit.  If you define all your vhosts in your httpd.conf file and 
not in included files, then you can enable mod_info in your Apache 
config, and restrict access to the information to localhost with 
something like:

  
SetHandler server-info
Order deny,allow
Deny from all
Allow from 127.0.0.1
  
Then your PHP code would hit your server's local /server-info link and 
parse it with something along the lines of:

  $info = file_get_contents('http://localhost/server-info?http_core.c');
  preg_match_all('/.*servername <.*?>(\S+?)<.*/i',$info,$reg);
  $vhosts = $reg[1];
You may need to doublecheck that regex.  I didn't actually test it.
-Rasmus
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Is it possible to save a file with UTF-8 encoding and noBOM using PHP?

2005-05-03 Thread Jon M.
Thanks also, Richard! You were right on.

Just a note:

I just visited the W3C validation service again, and it seems they have 
recently updated it. It no longer complains if it finds a BOM in your 
document binary. So it would appear that it's no longer an issue with enough 
XML parsers to be relevant anymore. Still, it is nice to have a 
program -like I do- that has that flexibility.

-Jon


"Richard Lynch" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Thu, April 28, 2005 4:14 am, Jon M. said:
>> No matter what I do to the strings to encode them in whatever format
>> before
>> using "fwrite", it ALWAYS seems to end up writing the actual file in
>> "iso-8859-1".
>
> How do you know?
>
> What are you using to determine the format of the file?
>
> We are contending that either you are *not* writing UTF-8 data, but are
> writing iso-8859-1 data, or the software telling you that it's not UTF-8
> is just plain *wrong*
>
> fwrite just takes your data and dumps it on the hard drive.
>
> It doesn't know UTF-8 from U2.
>
>> Isn't the encoding of the characters in PHP's strings, and the encoding 
>> of
>> the actual binary file on your hard drive, two totally different things?
>> Or
>> am I just misinformed?
>
> You are mis-informed.
>
>> How do you actually control the way the binary file itself is written, 
>> and
>> not just the text that is saved in the file?
>
> If you are using Windows, then *WINDOWS* is, perhaps, guessing on the
> binary format based on the file 'extension' (.txt) and on the contents.
>
> First, try renaming the file to, err, whatever Windows thinks UTF-8 file
> extensions should be... ".utf8" ??? Whatever Notepad uses.
>
> Next, forget what Windows desktop tells you.  It's bull.
>
> When you get the data back out of the file, what format is it?
>
> PS You may be confusing Windows by writing UTF-8 without the BOM, and so
> Windows then thinksit's iso-8859-1, because it's no longer a valid UTF-8
> file!  You can make Windows happy; or you can make W3c happy.  Not both.
>
> -- 
> Like Music?
> http://l-i-e.com/artists.htm 

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



RE: [PHP] is this possible in PHP?

2005-05-03 Thread Kim Madsen

> -Original Message-
> From: Dasmeet Singh [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, May 03, 2005 9:03 AM


> I want a script that can display a list of all the websites currently
> hosted on my server.. (i have root access to the server)
> 
> Say I have a page sitesonmyserver.php..it shud show a list of all the
> websites hosted on my server..eg:
> abc.com
> xyz.om
> 
> And any additional info if possible?
> 
> Is such a thing possible in PHP.. or does any such script exists?

If You´re running Apache, parse the httpd.conf and echo the line containing 
ServerName?


--
Med venlig hilsen / best regards
ComX Networks A/S
Kim Madsen
Systemudvikler/Systemdeveloper

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



[PHP] is this possible in PHP?

2005-05-03 Thread Dasmeet Singh
Hi!
I want a script that can display a list of all the websites currently 
hosted on my server.. (i have root access to the server)

Say I have a page sitesonmyserver.php..it shud show a list of all the 
websites hosted on my server..eg:
abc.com
xyz.om

And any additional info if possible?
Is such a thing possible in PHP.. or does any such script exists?
Thanks in advance!
Dasmeet
SayOrange.com
How to choose the best web hosting?
http://www.sayorange.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php