php-general Digest 9 Jan 2006 10:32:39 -0000 Issue 3895
Topics (messages 228303 through 228313):
strip leading zeros
228303 by: Ross
228304 by: Chris
228309 by: M. Sokolewicz
Power
228305 by: Khorosh Irani
228308 by: Dotan Cohen
No POST-Data available in Script when Handling ErrorDocument 404
228306 by: Oliver Hofer
Re: Remove atribute from links
228307 by: Dotan Cohen
Question generateing xml on v4.3
228310 by: Ted Zeng
safe mode question
228311 by: Robin
228312 by: Robin
Problem with fsockopen and SSL
228313 by: Barry
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:
php-general@lists.php.net
----------------------------------------------------------------------
--- Begin Message ---
Is there a PHP function to strip the leading zeros from a number/string.
R.
--- End Message ---
--- Begin Message ---
Ross wrote:
Is there a PHP function to strip the leading zeros from a number/string.
R.
You can use ltrim()
$sString = '0043680450';
$sString = ltrim($sString,'0');
http://www.php.net/ltrim
--- End Message ---
--- Begin Message ---
Ross wrote:
Is there a PHP function to strip the leading zeros from a number/string.
R.
try casting it to an (int) (if it's a number) and you'll have stripped
the 0's (or to a (float)/(double) if it's not an integer)
--- End Message ---
--- Begin Message ---
Hello
How I can get the power of an integer number (for example 8 power 2=64) only
with loops (without pow() function)?
Thanks
--- End Message ---
--- Begin Message ---
On 1/8/06, Khorosh Irani <[EMAIL PROTECTED]> wrote:
> Hello
> How I can get the power of an integer number (for example 8 power 2=64) only
> with loops (without pow() function)?
> Thanks
>
>
Is this for your homework? Untested:
<?php
$num=8;
$power=2;
for ($i=0; $i<$power;$i++) {
$num*=$num;
}
?>
Dotan Cohen
http://technology-sleuth.com/short_answer/what_is_hdtv.html
&^
)
--- End Message ---
--- Begin Message ---
I wrote a scritpt for testing SOAP-Services. It generates and sends
requests to other machines but also receives such requests from other
machines in the net.As there are many 'senders' and muc more URL's they
are sending their requests to, I intended to write a general
SOAP-Request handler, that handles all incoming requests.
Therefore I Configured Apache 2.0.55 using the ErrorDocument directive:
ErrorDocument 404 /soap/dispatcher.php
Now my tool is able to handle SOAP-Requests to any URL that is located
on the Server e.g. (ServerName = spttt.seraph)
http://spttt.seraph/bli/blo/foo (but also)
http://spttt.seraph/sifdino/services/OrderEntryRequestService
Hope you got the it so far.
Now my problem:
The Soap-Rquest handler needs to read the POST-Data that the sender of
the SOAP-Request posted to the script. $HTTP_RAW_POST_DATA should
contain this data but also php://input was mentioned in some
php-mailing-list messages I found in the archives.
My problem is, that my script NEVER gets any POST-Data, if it is called
by the ErrorDocument 404 Rule. If I address the handler directly, the
Post-Data ist there.
When the script is called by the apache errorDocument handler, the
following headers are received:
HTTP/1.1 404 Not Found
Date: Sun, 08 Jan 2006 00:48:45 GMT
Server: Apache/2.0.55 (Win32) PHP/5.1.1 DAV/2
X-Powered-By: PHP/5.1.1
Set-Cookie: PHPSESSID=0q9amr3s44k54i4lrv3no221k3; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0,
pre-check=0
Pragma: no-cache
Status: 200 OK
Content-Length: 1574
Content-Type: text/html; charset=ISO-8859-1
Array
(
[REDIRECT_REQUEST_METHOD] => POST
[REDIRECT_STATUS] => 404
[HTTP_HOST] => spttt.seraph
[CONTENT_TYPE] => text/xml
[CONTENT_LENGTH] => 25
[PATH] =>
C:\Programme\texmf\miktex\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Programme\cvsnt;C:\Programme\Microsoft
SQL Server\80\Tools\BINNC:\Programme\Gemeinsame Dateien\Ulead
Systems\MPEG;C:\Programme\Ulead Systems\Ulead FilmBrennerei 2
SE;C:\Programme\MySQL\MySQL Server
4.1\bin;C:\Programme\Subversion\bin;C:\Programme\QuickTime\QTSystem\
[SystemRoot] => C:\WINDOWS
[COMSPEC] => C:\WINDOWS\system32\cmd.exe
[PATHEXT] => .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
[WINDIR] => C:\WINDOWS
[SERVER_SIGNATURE] => <address>Apache/2.0.55 (Win32) PHP/5.1.1
DAV/2 Server at spttt.seraph Port 80</address>
[SERVER_SOFTWARE] => Apache/2.0.55 (Win32) PHP/5.1.1 DAV/2
[SERVER_NAME] => spttt.seraph
[SERVER_ADDR] => 192.168.44.100
[SERVER_PORT] => 80
[REMOTE_ADDR] => 192.168.44.100
[DOCUMENT_ROOT] => D:/projects/spttt/html
[SERVER_ADMIN] => [EMAIL PROTECTED]
[SCRIPT_FILENAME] => D:/projects/spttt/html/soap/dispatcher.php
[REMOTE_PORT] => 1863
[REDIRECT_URL] => /sptdino/services/OrderEntryRequestService
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => GET
[QUERY_STRING] =>
[REQUEST_URI] => /sptdino/services/OrderEntryRequestService
[SCRIPT_NAME] => /soap/dispatcher.php
[PHP_SELF] => /soap/dispatcher.php
[REQUEST_TIME] => 1136681325
)
Notice the REQUEST_METHOD, which is GET! Obviously the script get's no
POST-DATA in a GET-Request...
- Can anyone tell, if this behaviour is by intention?
- Why are the POST-Data not handed to the ErrorDocument - Script?
- Is there a possibility to solve this (workaround)?
- Im I stupid?
Below further information an my test-scripts:
Regards & thanks
Oli
Apache httpd.conf
<VirtualHost *:80>
ServerAdmin [EMAIL PROTECTED]
DocumentRoot D:/projects/spttt/html
ErrorDocument 404 /soap/dispatcher.php
ServerName spttt.seraph
ErrorLog logs/spt-error_log
CustomLog logs/spt-access_log common
</VirtualHost>
/soap/dispatcher.php (target for the ErrorDocument 404 directive)
<?php
header("Status:200 OK");
print_r($_SERVER);
$HTTP_RAW_POST_DATA = file_get_contents("php://input");
echo $HTTP_RAW_POST_DATA;
exit;
?>
posttest2.php (sends a POST-Request to an unknown URL on the Server
which should then be forwarded to the dispatcher.php by Apache
errorDocument-Handler)
<?php
$post_msg = '<request><bla/></request>';
$http_msg = "POST /sptdino/services/OrderEntryRequestService HTTP/1.1\r\n";
$http_msg .= "Host: spttt.seraph\r\n";
$http_msg .= "Content-Type: text/xml\r\n";
$http_msg .= "Content-Length:" .strlen($post_msg). "\r\n\r\n";
$http_msg .= $post_msg ."\r\n";
$http_msg;
$errno;
$errdesc;
$fp = @fsockopen("192.168.44.100", 80,$errno, $errdesc,15);
$reply = "";
if ($fp)
{
fputs ($fp, $http_msg);
while (!feof($fp))
{
$reply .= fgets($fp, 1024);
}
fclose ($fp);
}
echo($reply);
print_r($errdesc);
echo "done";
?>
Apache error-log states:
[Sun Jan 08 03:08:15 2006] [error] [client 192.168.44.100] File does not
exist: D:/projects/spttt/html/sptdino
--- End Message ---
--- Begin Message ---
On 1/8/06, Jared Williams <[EMAIL PROTECTED]> wrote:
>
> > I have an HTML document at home (the Firefox bookmarks
> > output) that I was trying to parse this morning, with many
> > links as such:
> > <a href="http://www.aximsite.com/articles/link.php?id=22"
> > add_date="1130275531" last_charset="windows-1252"
> > id="rdf:#$FOQot">Knowledge Base: What Can I Do With My Axim?</a>
> >
> > I want to parse it to remove the attributes add_date,
> > last_charset, id, and others that are in other entries. The
> > text of the file it produces is 22 kb but the HTML is over 500 kb!
> >
> > I don't have the code with me that I was trying (I'm not at
> > home now- but it has been nagging me all day), but I was
> > running into problems and could NOT get it to just remove the
> > attributes. One regex solution left me with <a></a> and
> > others with <>, <a href="http://address"
> > ="something" ="somehing else">blahblah</a>, etc...
> >
> > How can I get it to remove, say, attribute xxx and the ="something"
> > that follows it? In all fairness I am not good at regexes and
> > need to practice, but I would appreciate any help I can get-
> > I'm really bogged down with studies and simply cannot devote
> > a full day to this 'trivial' excercise.
>
> I'd forget regexps and use SAX style parser. Trivial then to remove unwanted
> attributes.
>
> Jared
>
>
Thanks. Looking into that now...
Dotan Cohen
http://technology-sleuth.com/short_answer/what_is_hdtv.html
*@
--- End Message ---
--- Begin Message ---
Hi,
I use OS X tiger which has a PHP v4.3.12 installed.
I would like to be able to generate xml files.
But when I copied a php script from a tutorial and tried it,
Php complaints that
domxml_new_doc is undefined function
How could that be?
Ted zeng
--- End Message ---
--- Begin Message ---
Hi:
I am running PHP 4.3.10 (cli) (built: Dec 11 2005 17:38:29) on SuSe 9.3 - and
am having some problems getting some scripts running.
php was compiled (by Suse) with:
Configure Command => './configure' '--prefix=/usr' '--datadir=/usr/share/php'
'--mandir=/usr/share/man' '--bindir=/usr/bin' '--libdir=/usr/share'
'--includedir=/usr/include' '--sysconfdir=/etc' '--with-_lib=lib'
'--with-config-file-path=/etc' '--with-exec-dir=/usr/lib/php/bin'
'--disable-debug' '--enable-inline-optimization' '--enable-memory-limit'
'--enable-magic-quotes' '--enable-safe-mode' '--enable-sigchild'
'--disable-ctype' '--disable-session' '--without-mysql' '--disable-cli'
'--without-pear' '--with-openssl' '--enable-force-cgi-redirect'
'--enable-discard-path' '--enable-cli' '--with-pear' 'i586-suse-linux'
(unrelated question - why have --enable-cli and --disable-cli?)
And I have safe mode off in php.ini,
safe_mode = Off
which is verified by a phpinfo();
safe_mode => Off => Off
However, the script should run from a cvs commit (the CVSROOT/logginfo
# BEGIN added by gforge-plugin-cvstracker
ALL ( php -q -d
include_path=.:/opt/gforge/gforge:/opt/gforge/gforge/www/include:/etc/gforge
/opt/gforge/gforge/plugins//cvstracker/bin/post.php %r %p %{sVv} )
# END added by gforge-plugin-cvstracker
And in /opt/gforge/gforge/plugins//cvstracker/bin/post.php, the code:
echo "safemode ";
echo ini_get('safe_mode');
Displays : "safemode 1"
I have tried the same thing from the command line, and the only way I can make
it the same, is to add the "-n" flag.
Any thoughts or pointers?
Thanks
-Robin
--- End Message ---
--- Begin Message ---
Doh -
I figured it out (for those who were interested). The permissions on
/etc/php.ini was set to 600 (owner == root). Changing this it other read, fixes
the issue.
Any idea why Suse would do this?
Thanks
-robin
--- End Message ---
--- Begin Message ---
Hi everyone!
I want to connect to an SSL server but i can't get the content :(
Here is the code i use:
$xml = '<xml><data>Hello!</data></xml>';
function PostToHost($host, $path, $referer, $data_to_send) {
$fp = fsockopen($host, 443);
printf("Open!\n");
fputs($fp, "POST $path HTTP/1.1\r\n\r\n");
fputs($fp, "Host:$host\r\n");
fputs($fp, "Referer: $referer\r\n");
fputs($fp, "Content-type: text/xml\r\n");
fputs($fp, "Content-length: ". strlen($data_to_send) ."\r\n");
fputs($fp, "Connection: close\r\n");
//fputs($fp, $data_to_send);
printf("Sent!\n");
while(!feof($fp)) {
$res .= fgets($fp, 128);
}
printf("Done!\n");
fclose($fp);
return $res;
}
$data = $xml;
printf("Go!\n");
$x = PostToHost(
"ssl://easy-demo.tcinternet.de",
"/hosting/servlet/Dispatcher",
$GLOBALS["HTTP_REFERER"],
$data
);
echo $x;
And this is what i get:
Go! Open! Sent! Done! HTTP/1.1 400 Bad Request Date: Mon, 09 Jan 2006
10:28:48 GMT Server: Apache/2.0.53 (Unix) mod_ssl/2.0.53 OpenSSL/0.9.7e
DAV/2 mod_jk/1.2.1 Content-Length: 363 Connection: close Content-Type:
text/html; charset=iso-8859-1
Bad Request
Your browser sent a request that this server could not understand.
Apache/2.0.53 (Unix) mod_ssl/2.0.53 OpenSSL/0.9.7e DAV/2 mod_jk/1.2.1
Server at easy-demo.tcinternet.de Port 443
What did the Webserver not understood?
Btw. i can't use cURL because the server has an old version of PHP (><)"
Would be glad if you can help or even have a code how to connect to a
SSL webserver via fsockopen that works.
Btw the PHP version on server is: PHP Version 4.2.2
Thanks for any help!
Greets Barry
--- End Message ---