[PHP] php newbie question with xml files
I have an xml document storing some data I need. What I want to do is this: 1. Scan to the end of the file. 2. Find the closing tag. 3. Insert a new entry in before the closing tag. I've tried: 1. Creating new files and renaming them to be the original. 2. Writing the file to a dummy file and insert my lines part way through then finish the last tag. My problem is I'm looking for a /endtag and it comes up as endtag. Is there anyway to force PHP to read the .xml file as a text file so it wont strip off the xml tag information? I've used fopen with fgets and fwrite, and file with fwrite Jared Sherman Totally lost newbie -- 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 noBOMusing PHP?
(Rasmus wrote:) If you fwrite UTF-8 data to the file, then it is a UTF-8 file. Thanks Rasmus! Honestly, that is REALLY helpful! I was just coming back here to post that I had found that very same answer. But I am glad to hear it confirmed by the experts. Bottom line: I was just being silly/ignorant. I went and downloaded a simple HEX editor and compared the actual binary output of several files that I had created using both PHP, and my favorite text editor (emeditor from emeditor.com). I then realized what probably everyone else here already knew: that (most of the time) the actual binary output from Windows 1252 and ISO-8859-1 and UTF-8 without the byte order mark -are completely identical! I had the false impression that when a file was saved in UTF-8, that there was an actual binary marker that specified this (e.g. binary marker = This file is saved in UTF-8!) -there simply is no such thing. The only thing that would set UTF-8 apart -binarilly speaking- is the BOM, and I had stripped that out, making the file exactly the same as plain old ANSI (since I didn't have any characters that required UTF-8, like from other languages etc.). My text editor displays the current character encoding in the status bar, but since there was no way for it to tell whether it was saved with Windows 1252 or UTF-8, it just displayed that the file was encoded windows default - ISO-8859-1. This is where I got confused. It turned out that my PHP script has been faithfully saving the file in UTF-8 the whole time, and everything was fine. I was just not educated enough about what actually changed when you save a file in UTF-8 but didn't have any characters that differed from ANSI (which in my case, the change was nothing, since ALL of the characters in my test document where interchangeable with ANSI). Well, this has been a learning experience! I hope that this post will help some poor ignoramus like myself, sometime in the future! :) And hopefully I am right about what I said above, and not flaunting my ignorance once again -lol Thanks again, to everyone who helped me! You guys really got me on the right track. Not the least of which was simply causing me to think about what I was asking more deeply. -Jon Rasmus Lerdorf [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Jon M. wrote: 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. 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? A file is completely defined by its contents. If you fwrite UTF-8 data to the file, then it is a UTF-8 file. Whether your editor, or whatever it is you are using to determine the file is being written as iso-8859-1 is smart enough to pick this up is a completely different question. Why don't you try creating the same contents with PHP and with your preferred text editor and then compare the contents. Perhaps your editor is dropping a hint somewhere in it that you are not writing to the file from PHP. -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] is this possible in PHP?
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
RE: [PHP] is this possible in PHP?
-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
Re: [PHP] Is it possible to save a file with UTF-8 encoding and noBOM using PHP?
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?
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: Location /server-info SetHandler server-info Order deny,allow Deny from all Allow from 127.0.0.1 /Location 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
[PHP] Merging Strings
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] Merging Strings
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