Re: [PHP] Re: news.php.net times out - unreachable for days
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. -- Lester Caine - G8HFL - L.S.Caine Electronic Services - http://home.lsces.co.uk Model Engineers Digital Workshop - http://home.lsces.co.uk/ModelEngineersDigitalWorkshop/ Treasurer - Firebird Foundation Inc. - http://www.firebirdsql.org/index.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Need help with RegEx
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 THIS IS A TEST 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>/"); 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
Re: [PHP] Need help with RegEx
explode it I'm having quite the difficulty to comprehend the regexp myself, but as a training, go ahead. On Monday 11 December 2006 09:02, 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 > > THIS IS A TEST > > 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>/"); > > 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 -- --- Børge Kennel Arivene http://www.arivene.net --- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Need help with RegEx
I'm no regex guru but something goes wrong here. First of you miss the second parameter in preg_match int preg_match ( string pattern, string subject [, array &matches [, int flags [, int offset]]] ) If you need the text from two unique tags it should not be to hard: $test = "THIS IS A TEST"; preg_match("/(.+?)<\/tag>/", $test, $matches); print_r($matches); Thijs On Mon, 11 Dec 2006 02:02:46 -0600, "Anthony Papillion" <[EMAIL PROTECTED]> 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 > > THIS IS A TEST > > 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>/"); > > 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
Re: [PHP] Need help with RegEx
# [EMAIL PROTECTED] / 2006-12-11 02:02:46 -0600: > 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 > > THIS IS A TEST > > 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>/"); > > The problem is that when I echo the value of $trans_text variable, I end up > with the entire HTML of the page. This is hardly the code you're actually using[1], can you please provide a piece of real code? [1] int preg_match ( string pattern, string subject [, array &matches [, int flags [, int offset]]] ) -- How many Vietnam vets does it take to screw in a light bulb? You don't know, man. You don't KNOW. Cause you weren't THERE. http://bash.org/?255991 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP - grabbing a thumb from FLV's (function)
i wanted to get my server to grab a thumbnail (video capture) of an FLV using PHP, and ffmpeg-php is not an option (at the moment, can't spare the possible downtime, many money-making sites involved). i installed ffmpeg. Fedora Core 4 users try this: yum install ffmpeg I went a more circuitous route and installed Subversion (SVN) (google it), THEN installed ffmpeg using the link on their download page. (get it, configure it, make it) Then, like i do with imageMagick, i use a system() call to ffmpeg. NOTE: (i had to put the full path to ffmpeg (usr/local/bin/ffmpeg) in my system call, this messed me up for a bit) here's my impromptu function (have to pass the FLV file, width, height, hour, min, sec, append (any value you want to put on the end of the resulting jpg's filename)): function flvThumb($file,$width=50,$height=50,$hour=00,$min=00,$sec=01,$append) { if ($append == "") { $append = time(); } if ($file == "" or !is_file($file)) { return false; } $width = eregi_replace("[^0-9]","",$width); $height = eregi_replace("[^0-9]","",$height); if ($width == "") { $width = 50; } if ($height == "") { $height = 50; } $hour = eregi_replace("[^0-9]","",$hour); $min = eregi_replace("[^0-9]","",$min); $sec = eregi_replace("[^0-9]","",$sec); if (strlen($hour) == 1) { $hour = "0" . $hour; } if (strlen($min) == 1) { $min = "0" . $min; } if (strlen($sec) == 1) { $sec = "0" . $sec; } $try = explode(".",$file); $ext = array_pop($try); $desig = implode(".",$try); $thumbname = $desig . "_" . $append . "." . "jpg"; $varmake = @system("/usr/local/bin/ffmpeg -i $file -vcodec png -vframes 1 -an -f rawvideo -s " . $width . "x" . $height . " -ss " . "$hour" . ":" . "$min" . ":" . "$sec" . " -y " . "$thumbname",$retval); $tmp = @stat($thumbname); if ($tmp['size'] == 0) { @unlink($thumbname); return false; } if ($retval != 0) { return false; } else { return $thumbname; } } if it returns anything but false, you may have a problem. of course, the problem may be with the function and application. i know that improvements can be made, but i wish i had seen this before i started trying to figure everything out. i like having a starting point. (i'm sending this to my gmail for my 'reference archive') HOPE THIS HELPS SOMEONE (plz don't burn me) 1337 c0d1ng 2 a11, & 2 a11 @ g00d n173, mellomutt p.s. it only just now strikes me that many other video formats can be thumbnailed. mpg, wmv, mov, avi, etc this really changes the way i'm thinking about my sites. i was using a desktop client to make thumbnails, and it's a good one, but to have ur server do it for you...that just makes it that much easier to add content, and thusly, that much more likely for me to add content because i'm a lazy wanker.
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 > >THIS IS A TEST > >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>/"); Using the tags you describe here, and assuming the source html is in the variable $source_html, try this: $trans_text = preg_replace("/(.*?)()(.*?)(<\/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 , the ? makes it non-greedy so that it stops after finding the first match. second atom () = 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 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 >
Re: [PHP] Need help with RegEx
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 >> >>THIS IS A TEST >> >>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>/"); > >Using the tags you describe here, and assuming the source html is in the >variable $source_html, try this: > >$trans_text = preg_replace("/(.*?)(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 , >the ? makes it non-greedy so that it stops after finding the first match. > >second atom () = 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 id=result_box dir=ltr> 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
RE: [PHP] Need help with RegEx
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: 16664 Rejected: Invalid LTV Example 2: Unable to Post, Invalid Information I want what is inside the 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 > > > >THIS IS A TEST > > > >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>/"); > > Using the tags you describe here, and assuming the source html is in the > variable $source_html, try this: > > $trans_text = preg_replace("/(.*?)( 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 dir=ltr>, > the ? makes it non-greedy so that it stops after finding the first match. > > second atom () = 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 id=result_box dir=ltr> 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
[PHP] pear xmlrpc question
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 Hola Jose ---END--- *Function Call:* helloWorld( Jose ) *Sent XML Message:* helloWorld Jose *Return Value:* *Received XML Message:* faultCode 2 faultString Invalid return payload: enable debugging to examine incoming payload ** 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 "Function Call: $function( $nombre )"; echo "Sent XML Message:"; echo "" . htmlentities($message->serialize()). ""; $value = $result->value(); echo "Return Value: $value "; echo "Received XML Message:"; echo "" . htmlentities($result->serialize()) . ""; 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. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
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): = = = 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: ~16664 Rejected: Invalid LTV Example 2: ~Unable to Post, Invalid Information I want what is inside the 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
RE: [PHP] Need help with RegEx
I got it. Hello, World!"; preg_match("#(.*?)#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): > > > $_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: > > ~16664 Rejected: Invalid LTV > > > Example 2: > > ~Unable to Post, Invalid Information > > > I want what is inside the 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 > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg_match to preg_replace
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 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? "; $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] = "$m2[0]"; $thestr = implode(" ", $m2); } elseif(count($m1)==1) { $thestr = $m2[0]; } else $thestr = ""; echo $thestr; echo ""; ?> Best regards, Peter Lauri www.dwsasia.com - company website www.lauri.se - personal website -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Need help with RegEx
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("/(.*?)(> 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>)(.*?)/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: > > 16664 Rejected: Invalid LTV > > >Example 2: > > Unable to Post, Invalid Information > > >I want what is inside the 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 >> > >> >THIS IS A TEST >> > >> >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>/"); >> >> Using the tags you describe here, and assuming the source html is in the >> variable $source_html, try this: >> >> $trans_text = preg_replace("/(.*?)(> 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>)(.*?)/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 > dir=ltr>, >> the ? makes it non-greedy so that it stops after finding the first match. >> >> second atom () = 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 > id=result_box dir=ltr> tag pair from $source_html, if there i
Re: [PHP] file uploads Q?
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. > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] file uploads Q?
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 --- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: news.php.net times out - unreachable for days
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 * -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: news.php.net times out - unreachable for days
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 * -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] file uploads Q?
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. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] flash/php file uploader
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] flash/php file uploader
> -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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] file uploads Q?
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/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHPDIG
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." -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHPDIG
r u planning to use it for intranet site or a internet site? if for a internet site: try http://www.google.com/coop instead of phpDig or HTDig saqib http://www.full-disk-encryption.net On 12/11/06, Leonard Burton <[EMAIL PROTECTED]> wrote: 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." -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Saqib Ali, CISSP, ISSAP http://www.full-disk-encryption.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] flash/php file uploader
Brad Fuller wrote: -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. PHP5.2.0 has this built in, see changelog: http://www.php.net/ChangeLog-5.php#5.2.0 and an example Rasmus previously posted: http://marc.theaimsgroup.com/?l=php-general&m=116265912901212&w=2 It's still ajax but the hooks are now built into php rather than an external unsupported patch. -- Postgresql & php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHPDIG
Thanks for the Google Tip. That is what I will use. Much easier as I don't think we will have 5,000 sites. Leonard On 12/11/06, Saqib Ali <[EMAIL PROTECTED]> wrote: r u planning to use it for intranet site or a internet site? if for a internet site: try http://www.google.com/coop instead of phpDig or HTDig saqib http://www.full-disk-encryption.net On 12/11/06, Leonard Burton <[EMAIL PROTECTED]> wrote: > 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." > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Saqib Ali, CISSP, ISSAP http://www.full-disk-encryption.net -- Leonard Burton, N9URK [EMAIL PROTECTED] "The prolonged evacuation would have dramatically affected the survivability of the occupants." -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Havn't been on the list in a while
Seems like this list has slowed down alot. Anybody else notice this, or am I just missing something? jl -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php