php-general Digest 12 Dec 2006 00:09:19 -0000 Issue 4509

Topics (messages 245707 through 245722):

Re: Need help with RegEx
        245707 by: Michael
        245708 by: Brad Fuller
        245710 by: tg-php.gryffyndevelopment.com
        245711 by: Brad Fuller
        245713 by: Michael

pear xmlrpc question
        245709 by: José Peso Echarri

preg_match to preg_replace
        245712 by: Peter Lauri

Re: file uploads Q?
        245714 by: Jochem Maas
        245715 by: Børge Holen
        245718 by: Jim Lucas
        245721 by: Chris

Re: news.php.net times out - unreachable for days
        245716 by: Chuck Anderson
        245717 by: Chuck Anderson

flash/php file uploader
        245719 by: Emil Edeholt
        245720 by: Brad Fuller

PHPDIG
        245722 by: Leonard Burton

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 ---
I just realized I neglected to explain a couple of things here, sorry...

My method will only work for the FIRST occurrence of the div tag pair in 
$source_html.

The reason this method works is that you are telling preg_replace to replace 
everything that matches the match pattern, with just what is contained in the 
third atom of the match pattern. Since we are matching everything between the 
start of $source_html and the end of $source_html (the (.*?) atom at the 
beginning, and the (.*?)^ atom at the end) your return value ends up being $3, 
or the contents of the third atom of the match pattern, which represents the 
text between the opening tag and closing tag of your div element.

hope this makes sense, I'm writing this at 5am heh

Cheers,
Michael

At 04:58 AM 12/11/2006 , Michael wrote:
>At 01:02 AM 12/11/2006 , Anthony Papillion wrote:
>>Hello Everyone,
>>
>>I am having a bit of problems wrapping my head around regular expressions. I 
>>thought I had a good grip on them but, for some reason, the expression I've 
>>created below simply doesn't work! Basically, I need to retreive all of the 
>>text between two unique and specific tags but I don't need the tag text. So 
>>let's say that the tag is
>>
>><tag lang='ttt'>THIS IS A TEST</tag>
>>
>>I would need to retreive THIS IS A TEST only and nothing else.
>>
>>Now, a bit more information: I am using cURL to retreive the entire contents 
>>of a webpage into a variable. I am then trying to perform the following 
>>regular expression on the retreived text:
>>
>>$trans_text = preg_match("\/<div id=result_box dir=ltr>(.+?)<\/div>/");
>
>Using the tags you describe here, and assuming the source html is in the
>variable $source_html, try this:
>
>$trans_text = preg_replace("/(.*?)(<div id=result_box
>dir=ltr>)(.*?)(<\/div>)(.*?)^/s","$3",$source_html);
>
>how this breaks down is:
> 
>opening quote for first parameter (your MATCH pattern).
>
>open regex match pattern= /
>
>first atom (.*?) = any or no leading text before <div id=result_box dir=ltr>,
>the ? makes it non-greedy so that it stops after finding the first match.
>
>second atom (<div id=result_box dir=ltr>) = the opening tag you are looking 
>for.
>
>third atom (.*?) = the text you want to strip out, all text even if nothing is
>there, between the 2nd and
>4th atoms.
>
>fourth atom (<\/div>) = the closing tag of the div tag pair.
>
>fifth atom (.*?) = all of the rest of the source html after the closing tag up
>to the end of the line ^,even if there is nothing there.
>
>close regex match pattern= /s
>
>in order for this to work on html that may contain newlines, you must specify
>that the . can represent newline characters, this is done by adding the letter
>'s' after your regex closing /, so the last thing in your regex match pattern
>would be /s.
>
>end of string ^ (this matches the end of the string you are matching/replacing
>, $source_html)
>
>closing quote for first parameter.
>
>The second parameter of the preg_replace is the atom # which contains the text
>you want to replace the text matched by the regex match pattern in the first
>parameter, in this case the text we want is in the third atom so this parameter
>would be $3 (this is the PHP way of back-referencing, if we wanted the text
>before the tag we would use atom 1, or $1, if we want the tag itself we use $2,
>etc basically a $ followed by the atom # that holds what we want to replace the
>$source_html into $trans_text).
>
>The third parameter of the preg_replace is the source you wish to match and
>replace from, in this case your source html in $source_html.
>
>after this executes, $trans_text should contain the innerText of the <div
>id=result_box dir=ltr></div> tag pair from $source_html, if there is nothing
>between the opening and closing tags, $trans_text will == "", if there is only
>a newline between the tags, $trans_text will == "\n". IMPORTANT: if the text
>between the tags contains a newline, $trans_text will also contain that newline
>character because we told . to match newlines.
>
>I am no regex expert by far, but this worked for me (assuming I copied it
>correctly here heh)
>There are doubtless many other ways to do this, and I am sure others on the
>list here will correct me if my way is wrong or inefficient.
>
>I hope this works for you and that I haven't horribly embarassed myself here.
>Good luck :)
>
>>
>>The problem is that when I echo the value of $trans_text variable, I end up 
>>with the entire HTML of the page.
>>
>>Can anyone clue me in to what I am doing wrong?
>>
>>Thanks,
>>Anthony 
>>
>>-- 
>>PHP General Mailing List (http://www.php.net/)
>>To unsubscribe, visit: http://www.php.net/unsub.php
>>  

--- End Message ---
--- Begin Message ---
The example provided didn't work for me.  It gave me the same string without
anything modified.

I am also looking for this solution to strip out text from some XML response
I get from posting data to a remote server.  I can do it using substring
functions but I'd like something more compact and portable. (A one-liner
that I could modify for other uses as well)

Example 1:
<someXMLtags>
        <status>16664 Rejected: Invalid LTV</status>
</someXMLtags>

Example 2:
<someXMLtags>
        <status>Unable to Post, Invalid Information</status>
</someXMLtags>

I want what is inside the <status> tags.

Does anyone have a working solution how we can get the text from inside
these tags using regex?

Much appreciated,

B

> -----Original Message-----
> From: Michael [mailto:[EMAIL PROTECTED]
> Sent: Monday, December 11, 2006 6:59 AM
> To: Anthony Papillion
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] Need help with RegEx
> 
> At 01:02 AM 12/11/2006 , Anthony Papillion wrote:
> >Hello Everyone,
> >
> >I am having a bit of problems wrapping my head around regular
> expressions. I
> >thought I had a good grip on them but, for some reason, the expression
> I've
> >created below simply doesn't work! Basically, I need to retreive all of
> the
> >text between two unique and specific tags but I don't need the tag text.
> So
> >let's say that the tag is
> >
> ><tag lang='ttt'>THIS IS A TEST</tag>
> >
> >I would need to retreive THIS IS A TEST only and nothing else.
> >
> >Now, a bit more information: I am using cURL to retreive the entire
> contents
> >of a webpage into a variable. I am then trying to perform the following
> >regular expression on the retreived text:
> >
> >$trans_text = preg_match("\/<div id=result_box dir=ltr>(.+?)<\/div>/");
> 
> Using the tags you describe here, and assuming the source html is in the
> variable $source_html, try this:
> 
> $trans_text = preg_replace("/(.*?)(<div id=result_box
> dir=ltr>)(.*?)(<\/div>)(.*?)^/s","$3",$source_html);
> 
> how this breaks down is:
> 
> opening quote for first parameter (your MATCH pattern).
> 
> open regex match pattern= /
> 
> first atom (.*?) = any or no leading text before <div id=result_box
> dir=ltr>,
> the ? makes it non-greedy so that it stops after finding the first match.
> 
> second atom (<div id=result_box dir=ltr>) = the opening tag you are
> looking for.
> 
> third atom (.*?) = the text you want to strip out, all text even if
> nothing is
> there, between the 2nd and
> 4th atoms.
> 
> fourth atom (<\/div>) = the closing tag of the div tag pair.
> 
> fifth atom (.*?) = all of the rest of the source html after the closing
> tag up
> to the end of the line ^,even if there is nothing there.
> 
> close regex match pattern= /s
> 
> in order for this to work on html that may contain newlines, you must
> specify
> that the . can represent newline characters, this is done by adding the
> letter
> 's' after your regex closing /, so the last thing in your regex match
> pattern
> would be /s.
> 
> end of string ^ (this matches the end of the string you are
> matching/replacing
> , $source_html)
> 
> closing quote for first parameter.
> 
> The second parameter of the preg_replace is the atom # which contains the
> text
> you want to replace the text matched by the regex match pattern in the
> first
> parameter, in this case the text we want is in the third atom so this
> parameter
> would be $3 (this is the PHP way of back-referencing, if we wanted the
> text
> before the tag we would use atom 1, or $1, if we want the tag itself we
> use $2,
> etc basically a $ followed by the atom # that holds what we want to
> replace the
> $source_html into $trans_text).
> 
> The third parameter of the preg_replace is the source you wish to match
> and
> replace from, in this case your source html in $source_html.
> 
> after this executes, $trans_text should contain the innerText of the <div
> id=result_box dir=ltr></div> tag pair from $source_html, if there is
> nothing
> between the opening and closing tags, $trans_text will == "", if there is
> only
> a newline between the tags, $trans_text will == "\n". IMPORTANT: if the
> text
> between the tags contains a newline, $trans_text will also contain that
> newline
> character because we told . to match newlines.
> 
> I am no regex expert by far, but this worked for me (assuming I copied it
> correctly here heh)
> There are doubtless many other ways to do this, and I am sure others on
> the
> list here will correct me if my way is wrong or inefficient.
> 
> I hope this works for you and that I haven't horribly embarassed myself
> here.
> Good luck :)
> 
> >
> >The problem is that when I echo the value of $trans_text variable, I end
> up
> >with the entire HTML of the page.
> >
> >Can anyone clue me in to what I am doing wrong?
> >
> >Thanks,
> >Anthony
> >
> >--
> >PHP General Mailing List (http://www.php.net/)
> >To unsubscribe, visit: http://www.php.net/unsub.php
> >

--- End Message ---
--- Begin Message ---
If you didn't say "using regex" this is how I'd do it  (untested, forgive typos 
and such..ripped from some code I actively use and stripped down):

<?PHP

  $_XML_RESPONSE_PARSER = xml_parser_create();
  xml_set_element_handler($_XML_RESPONSE_PARSER, 
'xml_response_open_element_function', 'xml_response_close_element_function');
  xml_set_character_data_handler($_XML_RESPONSE_PARSER, 
'xml_response_handle_character_data');
  xml_parse($_XML_RESPONSE_PARSER, $_XML_RESPONSE, strlen($_XML_RESPONSE));
  xml_parser_free($_XML_RESPONSE_PARSER);
~
  $FoundStatusTag = false;
~
  function xml_response_open_element_function($p, $element, $attributes) {
    global $FoundStatusTag;
~~
    if (strtoupper($element) == "STATUS") $FoundStatusTag = true;
  }
~
  function xml_response_close_element_function($p, $element){
    global $FoundStatusTag;
~  
    // do nothing special for now
  }
~
  function xml_response_handle_character_data($p, $cdata){ 
    global $FoundStatusTag;
~  
    if ($FoundStatusTag) {
      echo $cdata;
      $FoundStatusTag = false;
    }
  }

?>

= = = Original message = = =

The example provided didn't work for me.  It gave me the same string without
anything modified.

I am also looking for this solution to strip out text from some XML response
I get from posting data to a remote server.  I can do it using substring
functions but I'd like something more compact and portable. (A one-liner
that I could modify for other uses as well)

Example 1:
<someXMLtags>
~<status>16664 Rejected: Invalid LTV</status>
</someXMLtags>

Example 2:
<someXMLtags>
~<status>Unable to Post, Invalid Information</status>
</someXMLtags>

I want what is inside the <status> tags.

Does anyone have a working solution how we can get the text from inside
these tags using regex?

Much appreciated,

B


___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

--- End Message ---
--- Begin Message ---
I got it.

<?php
        $input = "<xmlJunk><status>Hello, World!</status></xmlJunk>";

        preg_match("#<status>(.*?)</status>#s", $input, $matches);
        echo $matches[1];
?>


> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Sent: Monday, December 11, 2006 10:59 AM
> To: php-general@lists.php.net
> Cc: [EMAIL PROTECTED]
> Subject: RE: [PHP] Need help with RegEx
> 
> If you didn't say "using regex" this is how I'd do it  (untested, forgive
> typos and such..ripped from some code I actively use and stripped down):
> 
> <?PHP
> 
>   $_XML_RESPONSE_PARSER = xml_parser_create();
>   xml_set_element_handler($_XML_RESPONSE_PARSER,
> 'xml_response_open_element_function',
> 'xml_response_close_element_function');
>   xml_set_character_data_handler($_XML_RESPONSE_PARSER,
> 'xml_response_handle_character_data');
>   xml_parse($_XML_RESPONSE_PARSER, $_XML_RESPONSE,
> strlen($_XML_RESPONSE));
>   xml_parser_free($_XML_RESPONSE_PARSER);
> ~
>   $FoundStatusTag = false;
> ~
>   function xml_response_open_element_function($p, $element, $attributes) {
>     global $FoundStatusTag;
> ~~
>     if (strtoupper($element) == "STATUS") $FoundStatusTag = true;
>   }
> ~
>   function xml_response_close_element_function($p, $element){
>     global $FoundStatusTag;
> ~
>     // do nothing special for now
>   }
> ~
>   function xml_response_handle_character_data($p, $cdata){
>     global $FoundStatusTag;
> ~
>     if ($FoundStatusTag) {
>       echo $cdata;
>       $FoundStatusTag = false;
>     }
>   }
> 
> ?>
> 
> = = = Original message = = =
> 
> The example provided didn't work for me.  It gave me the same string
> without
> anything modified.
> 
> I am also looking for this solution to strip out text from some XML
> response
> I get from posting data to a remote server.  I can do it using substring
> functions but I'd like something more compact and portable. (A one-liner
> that I could modify for other uses as well)
> 
> Example 1:
> <someXMLtags>
> ~<status>16664 Rejected: Invalid LTV</status>
> </someXMLtags>
> 
> Example 2:
> <someXMLtags>
> ~<status>Unable to Post, Invalid Information</status>
> </someXMLtags>
> 
> I want what is inside the <status> tags.
> 
> Does anyone have a working solution how we can get the text from inside
> these tags using regex?
> 
> Much appreciated,
> 
> B
> 
> 
> ___________________________________________________________
> Sent by ePrompter, the premier email notification software.
> Free download at http://www.ePrompter.com.
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

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

At 08:29 AM 12/11/2006 , Brad Fuller wrote:
>
>The example provided didn't work for me.  It gave me the same string without
>anything modified.

You are absolutely correct, this is what I get for not testing it explicitly :( 
My most sincere apologies to the OP and the list, there is an error in my 
example (see below for correction)

**** I have cut and pasted from further down in the quoted message, for 
convenience ****
>> Using the tags you describe here, and assuming the source html is in the
>> variable $source_html, try this:
>> 
>> $trans_text = preg_replace("/(.*?)(<div id=result_box
>> dir=ltr>)(.*?)(<\/div>)(.*?)^/s","$3",$source_html);

The End of string symbol ^ should not be included. I tested the above function 
without the ^ and it worked for me. below is the TESTED version:

$trans_text = preg_replace("/(.*?)(<div id=result_box 
dir=ltr>)(.*?)(<\/div>)(.*?)/s","$3",$source_html);
***** end of pasted section *****


>
>I am also looking for this solution to strip out text from some XML response
>I get from posting data to a remote server.  I can do it using substring
>functions but I'd like something more compact and portable. (A one-liner
>that I could modify for other uses as well)
>
>Example 1:
><someXMLtags>
>       <status>16664 Rejected: Invalid LTV</status>
></someXMLtags>
>
>Example 2:
><someXMLtags>
>       <status>Unable to Post, Invalid Information</status>
></someXMLtags>
>
>I want what is inside the <status> tags.
>
>Does anyone have a working solution how we can get the text from inside
>these tags using regex?
>
>Much appreciated,
>
>B
>
>> -----Original Message-----
>> From: Michael [mailto:[EMAIL PROTECTED]
>> Sent: Monday, December 11, 2006 6:59 AM
>> To: Anthony Papillion
>> Cc: php-general@lists.php.net
>> Subject: Re: [PHP] Need help with RegEx
>> 
>> At 01:02 AM 12/11/2006 , Anthony Papillion wrote:
>> >Hello Everyone,
>> >
>> >I am having a bit of problems wrapping my head around regular
>> expressions. I
>> >thought I had a good grip on them but, for some reason, the expression
>> I've
>> >created below simply doesn't work! Basically, I need to retreive all of
>> the
>> >text between two unique and specific tags but I don't need the tag text.
>> So
>> >let's say that the tag is
>> >
>> ><tag lang='ttt'>THIS IS A TEST</tag>
>> >
>> >I would need to retreive THIS IS A TEST only and nothing else.
>> >
>> >Now, a bit more information: I am using cURL to retreive the entire
>> contents
>> >of a webpage into a variable. I am then trying to perform the following
>> >regular expression on the retreived text:
>> >
>> >$trans_text = preg_match("\/<div id=result_box dir=ltr>(.+?)<\/div>/");
>> 
>> Using the tags you describe here, and assuming the source html is in the
>> variable $source_html, try this:
>> 
>> $trans_text = preg_replace("/(.*?)(<div id=result_box
>> dir=ltr>)(.*?)(<\/div>)(.*?)^/s","$3",$source_html);

The End of string symbol ^ should not be included. I tested the above function 
without the ^ and it worked for me. below is the TESTED version:

$trans_text = preg_replace("/(.*?)(<div id=result_box 
dir=ltr>)(.*?)(<\/div>)(.*?)/s","$3",$source_html);

>> 
>> how this breaks down is:
>> 
>> opening quote for first parameter (your MATCH pattern).
>> 
>> open regex match pattern= /
>> 
>> first atom (.*?) = any or no leading text before <div id=result_box
>> dir=ltr>,
>> the ? makes it non-greedy so that it stops after finding the first match.
>> 
>> second atom (<div id=result_box dir=ltr>) = the opening tag you are
>> looking for.
>> 
>> third atom (.*?) = the text you want to strip out, all text even if
>> nothing is
>> there, between the 2nd and
>> 4th atoms.
>> 
>> fourth atom (<\/div>) = the closing tag of the div tag pair.
>> 
>> fifth atom (.*?) = all of the rest of the source html after the closing
>> tag up
>> to the end of the line ^,even if there is nothing there.
>> 
>> close regex match pattern= /s
>> 
>> in order for this to work on html that may contain newlines, you must
>> specify
>> that the . can represent newline characters, this is done by adding the
>> letter
>> 's' after your regex closing /, so the last thing in your regex match
>> pattern
>> would be /s.
>> 
>> end of string ^ (this matches the end of the string you are
>> matching/replacing
>> , $source_html)

 ignore this part of the explanation, the ^ is not needed and in fact breaks 
the example given

>> 
>> closing quote for first parameter.
>> 
>> The second parameter of the preg_replace is the atom # which contains the
>> text
>> you want to replace the text matched by the regex match pattern in the
>> first
>> parameter, in this case the text we want is in the third atom so this
>> parameter
>> would be $3 (this is the PHP way of back-referencing, if we wanted the
>> text
>> before the tag we would use atom 1, or $1, if we want the tag itself we
>> use $2,
>> etc basically a $ followed by the atom # that holds what we want to
>> replace the
>> $source_html into $trans_text).
>> 
>> The third parameter of the preg_replace is the source you wish to match
>> and
>> replace from, in this case your source html in $source_html.
>> 
>> after this executes, $trans_text should contain the innerText of the <div
>> id=result_box dir=ltr></div> tag pair from $source_html, if there is
>> nothing
>> between the opening and closing tags, $trans_text will == "", if there is
>> only
>> a newline between the tags, $trans_text will == "\n". IMPORTANT: if the
>> text
>> between the tags contains a newline, $trans_text will also contain that
>> newline
>> character because we told . to match newlines.
>> 
>> I am no regex expert by far, but this worked for me (assuming I copied it
>> correctly here heh)
>> There are doubtless many other ways to do this, and I am sure others on
>> the
>> list here will correct me if my way is wrong or inefficient.
>> 
>> I hope this works for you and that I haven't horribly embarassed myself
>> here.
>> Good luck :)
>> 
>> >
>> >The problem is that when I echo the value of $trans_text variable, I end
>> up
>> >with the entire HTML of the page.
>> >
>> >Can anyone clue me in to what I am doing wrong?
>> >
>> >Thanks,
>> >Anthony
>> >
>> >--
>> >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
> 

--- End Message ---
--- Begin Message ---
I have a simple helloWorld example in a xmlrpc version.
The xmlrpc implementation that i have used is the pear package XML_RPC 1.5.1.

The problem ocurrs when the server send back the response, i always receive the error "Invalid return payload:enable debuggin..".
With debug enabled the output is this:

---GOT---
HTTP/1.1 200 OK
Date: Mon, 11 Dec 2006 16:37:42 GMT
Server: JWS (Unix) PHP/4.4.4 mod_fastcgi/2.4.2
X-Powered-By: PHP/4.4.4
Content-Length: 538
Connection: close
Content-Type: text/xml; charset=UTF-8


<?xml version="1.0" encoding="UTF-8"?>
<!-- PEAR XML_RPC SERVER DEBUG INFO:

0 - class xml_rpc_value {
var $me = array (
   'string' => 'Jose',
 );
 var $mytype = 1;
}
vvv POST DATA RECEIVED BY SERVER vvv
<?xml version="1.0" encoding="UTF-8"?>
<methodCall>
<methodName>helloWorld</methodName>
<params>
<param>
<value><string>Jose</string></value>
</param>
</params>
</methodCall>

^^^ END POST DATA ^^^
-->
<methodResponse>
<params>
<param>
<value><string>Hola Jose</string></value>
</param>
</params>
</methodResponse>

---END---

*Function Call:* helloWorld( Jose )

*Sent XML Message:*

<?xml version="1.0" encoding="UTF-8"?> <methodCall> <methodName>helloWorld</methodName> <params> <param> <value><string>Jose</string></value> </param> </params> </methodCall>

*Return Value:*

*Received XML Message:*

<methodResponse> <fault> <value> <struct> <member> <name>faultCode</name> <value><int>2</int></value> </member> <member> <name>faultString</name> <value><string>Invalid return payload: enable debugging to examine incoming payload</string></value> </member> </struct> </value> </fault> </methodResponse>





**************************

The client source code:

require_once("XML/RPC.php");
$nombre = "Jose";
$function = "helloWorld";
$p1 = new XML_RPC_Value($nombre, "string");
$params = array();
$params[] = $p1;

$message = new XML_RPC_Message($function, $params);

$client = new XML_RPC_Client("/pruebas/servicio.php", "www.wiloc.srv", 80);
$client->setDebug(true);
$result = $client->send($message);

echo "<p><b>Function Call:</b> $function( $nombre )</p>";
echo "<p><b>Sent XML Message:</b>";
echo "<pre>" . htmlentities($message->serialize()). "</pre></p>";

$value = $result->value();

echo "<p><b>Return Value:</b> $value </p>";
echo "<p><b>Received XML Message:</b>";
echo "<pre>" . htmlentities($result->serialize()) . "</pre></p>";
************************************


And the server source code:




**********************************
require_once("XML/RPC/Server.php");


$getnamelength_sig2 = array(array("string","string"));
$getnamelength_doc2 = "Hola mundo en xmlrpc";


function helloWorld($name)
{

$name1 = $name->getParam(0);
 $result = new XML_RPC_Value("Hola ".$name1->getval(), "string");

 return new XML_RPC_Response($result);
}




$map = array("helloWorld" =>
      array("function"  => "helloWorld",
            "signature" => $getnamelength_sig2,
            "docstring" => $getnamelength_doc2));
$server = new XML_RPC_Server($map,0,1);
$server->service();




What is wrong in this very simple example?


Thanks a lot,
Jose.

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

I have a sample string "[hp-ex][log]peter[hall o]" that I need to process. I
need to remove the [] and separate the sections with a space. If there are
more then one [] part the first part should be bold (add <b></b> around it).
I have a solution that is working very well, but am thinking that I can do
this with preg_replace directly, what do you think? The final output is
always found in $thestr. Can all this be done with one preg_replace?

<?php

echo "<pre>";

$str = "[hp-ex][log]peter[hall o]";

preg_match_all("/\[(.+?)\]/", $str, $matches);

print_r($matches);

$m1 = $matches[0];
$m2 = $matches[1];

if(count($m1)>1) {
        $m2[0] = "<b>$m2[0]</b>";
        $thestr = implode(" ", $m2);
} elseif(count($m1)==1) {
        $thestr = $m2[0];
} else $thestr = "";

echo $thestr;

echo "</pre>";

?>

Best regards,
Peter Lauri

www.dwsasia.com - company website
www.lauri.se - personal website

--- End Message ---
--- Begin Message ---
Richard Lynch wrote:
> On Sat, December 9, 2006 12:18 pm, William Stokes wrote:
>> Is it possible to allow  user pick several images and upload them all
>> at
>> once? (I need to pass the images to a function for the resize). Or do
>> I need
>> to give several browse buttons to allow multiple file uploads?
> 
> Yes, you would need to have several INPUT TYPE="FILE" browse buttons.
> 
>> Also I have seen a application (written with MS tools) that allows
>> user to
>> upload a zip file containing images and the zip is automatically
>> uncompressed to a server disk. Can this be done with PHP also?
> 
> Yes.
> http://php.net/zip

the zip extension is only available in php5.2 (or installable via
pecl).

another option would to use the exec() function to make a call to
gunzip in order to unpack the contents of the zip file.

a truely poorman's alternative would be to offer multiple FILE input
fields on the relevant page and check which one's are not empty when
the submission occurs.

lastly there are custom (usually java based) browser plugins capable
of providing uploads-on-steriods - obviously there would a purchasing cost
involved and more than likely you will be requried to implement something
server side to complete the functionality.

> 

--- End Message ---
--- Begin Message ---
On Monday 11 December 2006 20:48, Jochem Maas wrote:
> Richard Lynch wrote:
> > On Sat, December 9, 2006 12:18 pm, William Stokes wrote:
> >> Is it possible to allow  user pick several images and upload them all
> >> at
> >> once? (I need to pass the images to a function for the resize). Or do
> >> I need
> >> to give several browse buttons to allow multiple file uploads?
> >
> > Yes, you would need to have several INPUT TYPE="FILE" browse buttons.
> >
> >> Also I have seen a application (written with MS tools) that allows
> >> user to
> >> upload a zip file containing images and the zip is automatically
> >> uncompressed to a server disk. Can this be done with PHP also?
> >
> > Yes.
> > http://php.net/zip
>
> the zip extension is only available in php5.2 (or installable via
> pecl).
>
> another option would to use the exec() function to make a call to
> gunzip in order to unpack the contents of the zip file.
>
> a truely poorman's alternative would be to offer multiple FILE input
> fields on the relevant page and check which one's are not empty when
> the submission occurs.

there is no reason for checking each input.
Take a look at my earlier questions with the subject "A general UL script" and 
the replies with various ppl here 'bout the use of $_FILES.
This way it will check anything listed in the file(s) input of form(s).

>
> lastly there are custom (usually java based) browser plugins capable
> of providing uploads-on-steriods - obviously there would a purchasing cost
> involved and more than likely you will be requried to implement something
> server side to complete the functionality.

-- 
---
Børge
Kennel Arivene 
http://www.arivene.net
---

--- End Message ---
--- Begin Message ---
Jochem Maas wrote:
Richard Lynch wrote:
On Sat, December 9, 2006 12:18 pm, William Stokes wrote:
Is it possible to allow  user pick several images and upload them all
at
once? (I need to pass the images to a function for the resize). Or do
I need
to give several browse buttons to allow multiple file uploads?
Yes, you would need to have several INPUT TYPE="FILE" browse buttons.

Also I have seen a application (written with MS tools) that allows
user to
upload a zip file containing images and the zip is automatically
uncompressed to a server disk. Can this be done with PHP also?
Yes.
http://php.net/zip

the zip extension is only available in php5.2 (or installable via
pecl).

Just to let you know, you can read and unzip with v4.x but it has to be compiled in.

So, you would be able to READ a zip archive, but not WRITE one.

PHP 4 >= 4.1.0, and PECL is required
another option would to use the exec() function to make a call to
gunzip in order to unpack the contents of the zip file.

a truely poorman's alternative would be to offer multiple FILE input
fields on the relevant page and check which one's are not empty when
the submission occurs.

lastly there are custom (usually java based) browser plugins capable
of providing uploads-on-steriods - obviously there would a purchasing cost
involved and more than likely you will be requried to implement something
server side to complete the functionality.


--- End Message ---
--- Begin Message ---
Jim Lucas wrote:
Jochem Maas wrote:
Richard Lynch wrote:
On Sat, December 9, 2006 12:18 pm, William Stokes wrote:
Is it possible to allow  user pick several images and upload them all
at
once? (I need to pass the images to a function for the resize). Or do
I need
to give several browse buttons to allow multiple file uploads?
Yes, you would need to have several INPUT TYPE="FILE" browse buttons.

Also I have seen a application (written with MS tools) that allows
user to
upload a zip file containing images and the zip is automatically
uncompressed to a server disk. Can this be done with PHP also?
Yes.
http://php.net/zip

the zip extension is only available in php5.2 (or installable via
pecl).

Just to let you know, you can read and unzip with v4.x but it has to be compiled in.

So, you would be able to READ a zip archive, but not WRITE one.

PHP 4 >= 4.1.0, and PECL is required

There is also the pear class:

http://pear.php.net/package/File_Archive

No idea about what requirements that has, just another option. :)

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

--- End Message ---
--- Begin Message ---
Lester Caine wrote:
Chuck Anderson wrote:
In the time it takes to write a message, I lose my connection and often cannot even connect to send it.

I'm hurrying this time, so I hope it works.

(.... not that time ..... timed out ..... I'll try Sending again)

When I was forced to use the newsgroup interface I often had that problem, and I was complaining that I could not get eMails working :(

I've been running on emails for a while now after some kind fairy lifted the blocking of my email addresses, but I'm still using the newsgroup interface for a couple of php.net lists and nothing has changed there.


It was not like this until about two or three weeks ago. Prior to that it behaved like any other news server I connect to (it simply connected ... right away). Something has changed or broken.

(... It took three tries just to get this composition window to open with quoted material)

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
*****************************

--- End Message ---
--- Begin Message ---
Lester Caine wrote:
Chuck Anderson wrote:
In the time it takes to write a message, I lose my connection and often cannot even connect to send it.

I'm hurrying this time, so I hope it works.

(.... not that time ..... timed out ..... I'll try Sending again)

When I was forced to use the newsgroup interface I often had that problem, and I was complaining that I could not get eMails working :(

I've been running on emails for a while now after some kind fairy lifted the blocking of my email addresses, but I'm still using the newsgroup interface for a couple of php.net lists and nothing has changed there.


It was not like this until about two or three weeks ago. Prior to that it behaved like any other news server I connect to (it simply connected ... right away). Something has changed or broken.

(... It took three tries just to get this composition window to open with quoted material)

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
*****************************

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

Sorry if this is considered off topic, but do you know of any code examples/libs with a flash/php file uploader with progress bar?

I've googled for a while but the scripts I find won't work. I'm using Firefox 2 and Flash player 9 on an intel Mac if that tells you anything?

Or should I ask somewhere else?

Thanks for your time.

Emil

--- End Message ---
--- Begin Message ---
> -----Original Message-----
>
> Hi
> 
> Sorry if this is considered off topic, but do you know of any code
> examples/libs with a flash/php file uploader with progress bar?
> 
> I've googled for a while but the scripts I find won't work. I'm using
> Firefox 2 and Flash player 9 on an intel Mac if that tells you anything?
> 
> Or should I ask somewhere else?
> 
> Thanks for your time.
> 
> Emil

The problem with having a "real" progress bar with PHP is that by default
PHP does not have a callback function so you won't know the status of the
uploaded file until it's complete.

One way of overcoming this is to use a combination of AJAX+Perl/CGI instead
of PHP. (Most LAMP servers can also run CGI scripts)

An example of an upload progress bar written in AJAX+CGI is Filechucker. Our
company purchased a license for use on one of our sites, its cheap and works
great.

I have also seen custom PHP extensions that add the callback method, but
they require you to recompile PHP and in the end we decided to go with the
CGI solution as it was pretty much plug and play.

-B

--- End Message ---
--- Begin Message ---
HI Guys and Gals,

Has anyone used PHP Dig lately?

Is the new version any better than it used to be?

--
Leonard Burton, N9URK
[EMAIL PROTECTED]

"The prolonged evacuation would have dramatically affected the
survivability of the occupants."

--- End Message ---

Reply via email to