php-general Digest 4 Sep 2009 20:12:09 -0000 Issue 6322
php-general Digest 4 Sep 2009 20:12:09 - Issue 6322 Topics (messages 297663 through 297689): Re: Some help with SimpleXML :`( 297663 by: Matthew Croud 297664 by: J DeBord Re: What type of barcode used for document management system ? 297665 by: Sam Stelfox how to strip empty lines out of a txt using preg_replace() 297666 by: Ralph Deffke 297667 by: Ashley Sheridan 297668 by: Ralph Deffke 297669 by: Ashley Sheridan 297670 by: Ralph Deffke 297671 by: Ashley Sheridan 297672 by: Ralph Deffke 297673 by: Ashley Sheridan 297674 by: Martin Scotta 297675 by: Ralph Deffke 297676 by: Sam Stelfox 297677 by: Ralph Deffke 297678 by: Ashley Sheridan Re: Converting URL's to hyperlinks. 297679 by: Lupus Michaelis Re: Searching on AlphaNumeric Content Only 297680 by: Lupus Michaelis 297681 by: Ashley Sheridan 297682 by: Lupus Michaelis 297683 by: Lupus Michaelis php and ODBC 297684 by: Marc Fromm PHP inserting carriage returns into POST values? 297685 by: James Colannino 297686 by: Andrew Ballard 297689 by: James Colannino Include Files in HTML 297687 by: sono-io.fannullone.us 297688 by: Bob McConnell Administrivia: To subscribe to the digest, e-mail: php-general-digest-subscr...@lists.php.net To unsubscribe from the digest, e-mail: php-general-digest-unsubscr...@lists.php.net To post to the list, e-mail: php-gene...@lists.php.net -- ---BeginMessage--- Well, you guys are awesome. So the script below doesn't cause any errors (nice), however it doesn't save the newly added child to the xml file (items.xml): $xml = simplexml_load_file(items.xml); $item = $xml-addChild('item'); $item-addChild('name', $name); $item-addChild('desc', $desc); $item-addChild('size', $size); $item-addChild('price', $price); I thought it would ? would i need to write using fwrite ? ---End Message--- ---BeginMessage--- On Fri, Sep 4, 2009 at 10:23 AM, Matthew Croud m...@obviousdigital.comwrote: Well, you guys are awesome. So the script below doesn't cause any errors (nice), however it doesn't save the newly added child to the xml file (items.xml): $xml = simplexml_load_file(items.xml); $item = $xml-addChild('item'); $item-addChild('name', $name); $item-addChild('desc', $desc); $item-addChild('size', $size); $item-addChild('price', $price); I thought it would ? would i need to write using fwrite ? You'll need to save your xml to the file once you are done manipulating it. Use $xml-asXML('filename'); Check here: http://www.php.net/manual/en/simplexmlelement.asXML.php J -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php ---End Message--- ---BeginMessage--- As a matter of fact... For a while I was using a barcode generator to test out inventory system before getting them professionally made. I personally chose to go with Interleaved 2 of 5 as our barcode scanner was able to read them accurately and it was the same format as our campus ID cards. The trick with this is that it only supports numbers. Code128 has three different encoding tables, table B which is most commonly used, includes the characters 0-9, A-Z, a-z and a handful of symbols which I don't remember of the top of my head. I used a class someone else made which can be found here: http://www.phpclasses.org/browse/package/2176.html The code itself is quite ugly but as it was only needed temporarily it worked. It might be a good starting point for you though. aveev wrote: Hi, I'm new to using barcode I want to create an online registration in my application, where the user can fill in the form and the application will create a pdf file of the form with the barcode inserted on it. The user then brings the printed form to us and we scan the barcode. After scanning the barcode and verifying the user data, we will proceed to decide whether his/her application is approved or not. I'm using fpdf to create the pdf file and for the barcode, I'm still looking for suitable solution. I don't know what type of barcode I should use for this purpose (I've browsed internet and found out many types of barcodes..e.g 39, 93, ean-13, c128, etc). Has anyone used php and barcode generator with their application ?? Thanks ---End Message--- ---BeginMessage--- Hi all, I'm a bit under stress, maybe somebody knows the regex on a snap. using PHP_EOL would be great. thanks ralph_def...@yahoo.de ---End Message--- ---BeginMessage--- On Fri, 2009-09-04 at 14:58 +0200, Ralph Deffke wrote: Hi all, I'm a bit under stress, maybe somebody knows the regex on a snap. using PHP_EOL would be great. thanks ralph_def...@yahoo.de The regex that would match a line containing only
[PHP] What type of barcode used for document management system ?
Hi, I'm new to using barcode I want to create an online registration in my application, where the user can fill in the form and the application will create a pdf file of the form with the barcode inserted on it. The user then brings the printed form to us and we scan the barcode. After scanning the barcode and verifying the user data, we will proceed to decide whether his/her application is approved or not. I'm using fpdf to create the pdf file and for the barcode, I'm still looking for suitable solution. I don't know what type of barcode I should use for this purpose (I've browsed internet and found out many types of barcodes..e.g 39, 93, ean-13, c128, etc). Has anyone used php and barcode generator with their application ?? Thanks -- View this message in context: http://www.nabble.com/What-type-of-barcode-used-for-document-management-system---tp25289483p25289483.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Some help with SimpleXML :`(
Well, you guys are awesome. So the script below doesn't cause any errors (nice), however it doesn't save the newly added child to the xml file (items.xml): $xml = simplexml_load_file(items.xml); $item = $xml-addChild('item'); $item-addChild('name', $name); $item-addChild('desc', $desc); $item-addChild('size', $size); $item-addChild('price', $price); I thought it would ? would i need to write using fwrite ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Some help with SimpleXML :`(
On Fri, Sep 4, 2009 at 10:23 AM, Matthew Croud m...@obviousdigital.comwrote: Well, you guys are awesome. So the script below doesn't cause any errors (nice), however it doesn't save the newly added child to the xml file (items.xml): $xml = simplexml_load_file(items.xml); $item = $xml-addChild('item'); $item-addChild('name', $name); $item-addChild('desc', $desc); $item-addChild('size', $size); $item-addChild('price', $price); I thought it would ? would i need to write using fwrite ? You'll need to save your xml to the file once you are done manipulating it. Use $xml-asXML('filename'); Check here: http://www.php.net/manual/en/simplexmlelement.asXML.php J -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] What type of barcode used for document management system ?
As a matter of fact... For a while I was using a barcode generator to test out inventory system before getting them professionally made. I personally chose to go with Interleaved 2 of 5 as our barcode scanner was able to read them accurately and it was the same format as our campus ID cards. The trick with this is that it only supports numbers. Code128 has three different encoding tables, table B which is most commonly used, includes the characters 0-9, A-Z, a-z and a handful of symbols which I don't remember of the top of my head. I used a class someone else made which can be found here: http://www.phpclasses.org/browse/package/2176.html The code itself is quite ugly but as it was only needed temporarily it worked. It might be a good starting point for you though. aveev wrote: Hi, I'm new to using barcode I want to create an online registration in my application, where the user can fill in the form and the application will create a pdf file of the form with the barcode inserted on it. The user then brings the printed form to us and we scan the barcode. After scanning the barcode and verifying the user data, we will proceed to decide whether his/her application is approved or not. I'm using fpdf to create the pdf file and for the barcode, I'm still looking for suitable solution. I don't know what type of barcode I should use for this purpose (I've browsed internet and found out many types of barcodes..e.g 39, 93, ean-13, c128, etc). Has anyone used php and barcode generator with their application ?? Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] how to strip empty lines out of a txt using preg_replace()
Hi all, I'm a bit under stress, maybe somebody knows the regex on a snap. using PHP_EOL would be great. thanks ralph_def...@yahoo.de -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how to strip empty lines out of a txt using preg_replace()
On Fri, 2009-09-04 at 14:58 +0200, Ralph Deffke wrote: Hi all, I'm a bit under stress, maybe somebody knows the regex on a snap. using PHP_EOL would be great. thanks ralph_def...@yahoo.de The regex that would match a line containing only whitespace would look like this: ^\s*$ Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how to strip empty lines out of a txt using preg_replace()
ok preg_replace( /^\s*$/m, , $somestring) does not take empty lines out Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1252069539.24700.150.ca...@localhost... On Fri, 2009-09-04 at 14:58 +0200, Ralph Deffke wrote: Hi all, I'm a bit under stress, maybe somebody knows the regex on a snap. using PHP_EOL would be great. thanks ralph_def...@yahoo.de The regex that would match a line containing only whitespace would look like this: ^\s*$ Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how to strip empty lines out of a txt using preg_replace()
On Fri, 2009-09-04 at 15:28 +0200, Ralph Deffke wrote: ok preg_replace( /^\s*$/m, , $somestring) does not take empty lines out Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1252069539.24700.150.ca...@localhost... On Fri, 2009-09-04 at 14:58 +0200, Ralph Deffke wrote: Hi all, I'm a bit under stress, maybe somebody knows the regex on a snap. using PHP_EOL would be great. thanks ralph_def...@yahoo.de The regex that would match a line containing only whitespace would look like this: ^\s*$ Thanks, Ash http://www.ashleysheridan.co.uk Are the lines actually whitespace, or are they actually br/ tags that are inserting lines to format the page for HTML display? Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how to strip empty lines out of a txt using preg_replace()
the problem is some have got \t\n some are just \n\n\n using PHP_EOL is a must I thing must be something with the /../sm attributes to the regex, spend like half an hour, but didn't get it, I'm running against a dead line, doesn't seem to be that easy if regex is not the everydays need u have Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1252071327.24700.152.ca...@localhost... On Fri, 2009-09-04 at 15:28 +0200, Ralph Deffke wrote: ok preg_replace( /^\s*$/m, , $somestring) does not take empty lines out Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1252069539.24700.150.ca...@localhost... On Fri, 2009-09-04 at 14:58 +0200, Ralph Deffke wrote: Hi all, I'm a bit under stress, maybe somebody knows the regex on a snap. using PHP_EOL would be great. thanks ralph_def...@yahoo.de The regex that would match a line containing only whitespace would look like this: ^\s*$ Thanks, Ash http://www.ashleysheridan.co.uk Are the lines actually whitespace, or are they actually br/ tags that are inserting lines to format the page for HTML display? Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how to strip empty lines out of a txt using preg_replace()
On Fri, 2009-09-04 at 15:37 +0200, Ralph Deffke wrote: the problem is some have got \t\n some are just \n\n\n using PHP_EOL is a must I thing must be something with the /../sm attributes to the regex, spend like half an hour, but didn't get it, I'm running against a dead line, doesn't seem to be that easy if regex is not the everydays need u have Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1252071327.24700.152.ca...@localhost... On Fri, 2009-09-04 at 15:28 +0200, Ralph Deffke wrote: ok preg_replace( /^\s*$/m, , $somestring) does not take empty lines out Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1252069539.24700.150.ca...@localhost... On Fri, 2009-09-04 at 14:58 +0200, Ralph Deffke wrote: Hi all, I'm a bit under stress, maybe somebody knows the regex on a snap. using PHP_EOL would be great. thanks ralph_def...@yahoo.de The regex that would match a line containing only whitespace would look like this: ^\s*$ Thanks, Ash http://www.ashleysheridan.co.uk Are the lines actually whitespace, or are they actually br/ tags that are inserting lines to format the page for HTML display? Thanks, Ash http://www.ashleysheridan.co.uk If it is just made up of \t and \n then \s in the regex should match it, as it's meant to match just whitespace characters. Where are you getting the content from anyway? Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how to strip empty lines out of a txt using preg_replace()
I'm working on DTD's Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1252071932.24700.153.ca...@localhost... On Fri, 2009-09-04 at 15:37 +0200, Ralph Deffke wrote: the problem is some have got \t\n some are just \n\n\n using PHP_EOL is a must I thing must be something with the /../sm attributes to the regex, spend like half an hour, but didn't get it, I'm running against a dead line, doesn't seem to be that easy if regex is not the everydays need u have Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1252071327.24700.152.ca...@localhost... On Fri, 2009-09-04 at 15:28 +0200, Ralph Deffke wrote: ok preg_replace( /^\s*$/m, , $somestring) does not take empty lines out Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1252069539.24700.150.ca...@localhost... On Fri, 2009-09-04 at 14:58 +0200, Ralph Deffke wrote: Hi all, I'm a bit under stress, maybe somebody knows the regex on a snap. using PHP_EOL would be great. thanks ralph_def...@yahoo.de The regex that would match a line containing only whitespace would look like this: ^\s*$ Thanks, Ash http://www.ashleysheridan.co.uk Are the lines actually whitespace, or are they actually br/ tags that are inserting lines to format the page for HTML display? Thanks, Ash http://www.ashleysheridan.co.uk If it is just made up of \t and \n then \s in the regex should match it, as it's meant to match just whitespace characters. Where are you getting the content from anyway? Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how to strip empty lines out of a txt using preg_replace()
On Fri, 2009-09-04 at 15:45 +0200, Ralph Deffke wrote: I'm working on DTD's Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1252071932.24700.153.ca...@localhost... On Fri, 2009-09-04 at 15:37 +0200, Ralph Deffke wrote: the problem is some have got \t\n some are just \n\n\n using PHP_EOL is a must I thing must be something with the /../sm attributes to the regex, spend like half an hour, but didn't get it, I'm running against a dead line, doesn't seem to be that easy if regex is not the everydays need u have Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1252071327.24700.152.ca...@localhost... On Fri, 2009-09-04 at 15:28 +0200, Ralph Deffke wrote: ok preg_replace( /^\s*$/m, , $somestring) does not take empty lines out Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1252069539.24700.150.ca...@localhost... On Fri, 2009-09-04 at 14:58 +0200, Ralph Deffke wrote: Hi all, I'm a bit under stress, maybe somebody knows the regex on a snap. using PHP_EOL would be great. thanks ralph_def...@yahoo.de The regex that would match a line containing only whitespace would look like this: ^\s*$ Thanks, Ash http://www.ashleysheridan.co.uk Are the lines actually whitespace, or are they actually br/ tags that are inserting lines to format the page for HTML display? Thanks, Ash http://www.ashleysheridan.co.uk If it is just made up of \t and \n then \s in the regex should match it, as it's meant to match just whitespace characters. Where are you getting the content from anyway? Thanks, Ash http://www.ashleysheridan.co.uk OK, but where are they coming from? Are they as external files or what? Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how to strip empty lines out of a txt using preg_replace()
On Fri, Sep 4, 2009 at 10:37 AM, Ralph Deffke ralph_def...@yahoo.de wrote: the problem is some have got \t\n some are just \n\n\n using PHP_EOL is a must I thing must be something with the /../sm attributes to the regex, spend like half an hour, but didn't get it, I'm running against a dead line, doesn't seem to be that easy if regex is not the everydays need u have Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1252071327.24700.152.ca...@localhost... On Fri, 2009-09-04 at 15:28 +0200, Ralph Deffke wrote: ok preg_replace( /^\s*$/m, , $somestring) does not take empty lines out Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1252069539.24700.150.ca...@localhost... On Fri, 2009-09-04 at 14:58 +0200, Ralph Deffke wrote: Hi all, I'm a bit under stress, maybe somebody knows the regex on a snap. using PHP_EOL would be great. thanks ralph_def...@yahoo.de The regex that would match a line containing only whitespace would look like this: ^\s*$ Thanks, Ash http://www.ashleysheridan.co.uk Are the lines actually whitespace, or are they actually br/ tags that are inserting lines to format the page for HTML display? Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php The PHP_EOL is system dependent. If you want a solution that works on every type of file you have to code it yourself. Here you have a function made some time ago. Maybe you can improve it. If you want the result as a text format you can implode( PHP_EOL, $buffer ) Hope this helps you. function explode($code) { $lines = array(); $buffer = ''; for($i=0, $len = strlen($code); $i$len; ++$i) switch( $code{$i} ) { case \r: case \n: if( $i+1 == $len ) break 2; if( \r == ($next = $code{ $i+1 }) || \n == $next ) { ++$i; } $lines[] = $buffer; $buffer = ''; break; default: $buffer .= $code{$i}; } if( '' !== $buffer ); $lines[] = $buffer; return $lines; } -- Martin Scotta
Re: [PHP] how to strip empty lines out of a txt using preg_replace()
this works $dtd = preg_replace( /\n+/, \n, $dtd); Martin Scotta martinsco...@gmail.com wrote in message news:6445d94e0909040653i44716f79m972f11055599...@mail.gmail.com... On Fri, Sep 4, 2009 at 10:37 AM, Ralph Deffke ralph_def...@yahoo.de wrote: the problem is some have got \t\n some are just \n\n\n using PHP_EOL is a must I thing must be something with the /../sm attributes to the regex, spend like half an hour, but didn't get it, I'm running against a dead line, doesn't seem to be that easy if regex is not the everydays need u have Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1252071327.24700.152.ca...@localhost... On Fri, 2009-09-04 at 15:28 +0200, Ralph Deffke wrote: ok preg_replace( /^\s*$/m, , $somestring) does not take empty lines out Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1252069539.24700.150.ca...@localhost... On Fri, 2009-09-04 at 14:58 +0200, Ralph Deffke wrote: Hi all, I'm a bit under stress, maybe somebody knows the regex on a snap. using PHP_EOL would be great. thanks ralph_def...@yahoo.de The regex that would match a line containing only whitespace would look like this: ^\s*$ Thanks, Ash http://www.ashleysheridan.co.uk Are the lines actually whitespace, or are they actually br/ tags that are inserting lines to format the page for HTML display? Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php The PHP_EOL is system dependent. If you want a solution that works on every type of file you have to code it yourself. Here you have a function made some time ago. Maybe you can improve it. If you want the result as a text format you can implode( PHP_EOL, $buffer ) Hope this helps you. function explode($code) { $lines = array(); $buffer = ''; for($i=0, $len = strlen($code); $i$len; ++$i) switch( $code{$i} ) { case \r: case \n: if( $i+1 == $len ) break 2; if( \r == ($next = $code{ $i+1 }) || \n == $next ) { ++$i; } $lines[] = $buffer; $buffer = ''; break; default: $buffer .= $code{$i}; } if( '' !== $buffer ); $lines[] = $buffer; return $lines; } -- Martin Scotta -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how to strip empty lines out of a txt using preg_replace()
The following snippet is untested and using Ash's regex (it is accurate \s matches any white space). $content is what is getting stripped of the new lines and $filtered is the cleansed output. See if that does the trick for you. $lines = str_split(PHP_EOL, $content); $filtered = ''; foreach ($lines as $line) { if (!preg_match('^\s*$', $line)) { // Splitting on the PHP_EOL characters cause it to be removed be sure to put it back $filtered .= $line . PHP_EOL; } } Ralph Deffke wrote: the problem is some have got \t\n some are just \n\n\n using PHP_EOL is a must I thing must be something with the /../sm attributes to the regex, spend like half an hour, but didn't get it, I'm running against a dead line, doesn't seem to be that easy if regex is not the everydays need u have Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1252071327.24700.152.ca...@localhost... On Fri, 2009-09-04 at 15:28 +0200, Ralph Deffke wrote: ok preg_replace( /^\s*$/m, , $somestring) does not take empty lines out Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1252069539.24700.150.ca...@localhost... On Fri, 2009-09-04 at 14:58 +0200, Ralph Deffke wrote: Hi all, I'm a bit under stress, maybe somebody knows the regex on a snap. using PHP_EOL would be great. thanks ralph_def...@yahoo.de The regex that would match a line containing only whitespace would look like this: ^\s*$ Thanks, Ash http://www.ashleysheridan.co.uk Are the lines actually whitespace, or are they actually br/ tags that are inserting lines to format the page for HTML display? Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] how to strip empty lines out of a txt using preg_replace()
and this is the PHP_EOL solution: $dtd = preg_replace( /[. PHP_EOL . ]+/, . PHP_EOL . , $dtd); dont ask me why two empty strings are needed to surround the PHP_EOL but its does it. Why this works? we have got an INTERPRETER here any \n is transtlated into 0x0D an \r into 0x0A so the pattern does not reach prce as '\n' hehe Martin Scotta martinsco...@gmail.com wrote in message news:6445d94e0909040653i44716f79m972f11055599...@mail.gmail.com... On Fri, Sep 4, 2009 at 10:37 AM, Ralph Deffke ralph_def...@yahoo.de wrote: the problem is some have got \t\n some are just \n\n\n using PHP_EOL is a must I thing must be something with the /../sm attributes to the regex, spend like half an hour, but didn't get it, I'm running against a dead line, doesn't seem to be that easy if regex is not the everydays need u have Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1252071327.24700.152.ca...@localhost... On Fri, 2009-09-04 at 15:28 +0200, Ralph Deffke wrote: ok preg_replace( /^\s*$/m, , $somestring) does not take empty lines out Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1252069539.24700.150.ca...@localhost... On Fri, 2009-09-04 at 14:58 +0200, Ralph Deffke wrote: Hi all, I'm a bit under stress, maybe somebody knows the regex on a snap. using PHP_EOL would be great. thanks ralph_def...@yahoo.de The regex that would match a line containing only whitespace would look like this: ^\s*$ Thanks, Ash http://www.ashleysheridan.co.uk Are the lines actually whitespace, or are they actually br/ tags that are inserting lines to format the page for HTML display? Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php The PHP_EOL is system dependent. If you want a solution that works on every type of file you have to code it yourself. Here you have a function made some time ago. Maybe you can improve it. If you want the result as a text format you can implode( PHP_EOL, $buffer ) Hope this helps you. function explode($code) { $lines = array(); $buffer = ''; for($i=0, $len = strlen($code); $i$len; ++$i) switch( $code{$i} ) { case \r: case \n: if( $i+1 == $len ) break 2; if( \r == ($next = $code{ $i+1 }) || \n == $next ) { ++$i; } $lines[] = $buffer; $buffer = ''; break; default: $buffer .= $code{$i}; } if( '' !== $buffer ); $lines[] = $buffer; return $lines; } -- Martin Scotta -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how to strip empty lines out of a txt using preg_replace()
On Fri, 2009-09-04 at 16:13 +0200, Ralph Deffke wrote: and this is the PHP_EOL solution: $dtd = preg_replace( /[. PHP_EOL . ]+/, . PHP_EOL . , $dtd); dont ask me why two empty strings are needed to surround the PHP_EOL but its does it. Why this works? we have got an INTERPRETER here any \n is transtlated into 0x0D an \r into 0x0A so the pattern does not reach prce as '\n' hehe Martin Scotta martinsco...@gmail.com wrote in message news:6445d94e0909040653i44716f79m972f11055599...@mail.gmail.com... On Fri, Sep 4, 2009 at 10:37 AM, Ralph Deffke ralph_def...@yahoo.de wrote: the problem is some have got \t\n some are just \n\n\n using PHP_EOL is a must I thing must be something with the /../sm attributes to the regex, spend like half an hour, but didn't get it, I'm running against a dead line, doesn't seem to be that easy if regex is not the everydays need u have Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1252071327.24700.152.ca...@localhost... On Fri, 2009-09-04 at 15:28 +0200, Ralph Deffke wrote: ok preg_replace( /^\s*$/m, , $somestring) does not take empty lines out Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1252069539.24700.150.ca...@localhost... On Fri, 2009-09-04 at 14:58 +0200, Ralph Deffke wrote: Hi all, I'm a bit under stress, maybe somebody knows the regex on a snap. using PHP_EOL would be great. thanks ralph_def...@yahoo.de The regex that would match a line containing only whitespace would look like this: ^\s*$ Thanks, Ash http://www.ashleysheridan.co.uk Are the lines actually whitespace, or are they actually br/ tags that are inserting lines to format the page for HTML display? Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php The PHP_EOL is system dependent. If you want a solution that works on every type of file you have to code it yourself. Here you have a function made some time ago. Maybe you can improve it. If you want the result as a text format you can implode( PHP_EOL, $buffer ) Hope this helps you. function explode($code) { $lines = array(); $buffer = ''; for($i=0, $len = strlen($code); $i$len; ++$i) switch( $code{$i} ) { case \r: case \n: if( $i+1 == $len ) break 2; if( \r == ($next = $code{ $i+1 }) || \n == $next ) { ++$i; } $lines[] = $buffer; $buffer = ''; break; default: $buffer .= $code{$i}; } if( '' !== $buffer ); $lines[] = $buffer; return $lines; } -- Martin Scotta The empty strings are forcing the parameter to be used as a string, otherwise the line would be translated as something like this: $dtd = preg_replace( /\n/, \n, $dtd); Notice how that newline character is actually just the character by itself, and is not a string. Obviously, the exact end of line character will differ from system to system, but this is a simple example of exactly why you had to concatenate the PHP_EOL with those empty strings. Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Converting URL's to hyperlinks.
Daevid Vincent a écrit : Maybe I misunderstood the OP, OP ? but wouldn't this (or something like it) be easier and cleaner than that mess below?? No, it's dirty too. $url = preg_replace(/(\...@\w+\.[a-za-z]{2,3})/i, a href='mailto:$1'$1/a, $url); This violate the numerous RFC about mail addresses, and some other stuffs. $url = preg_replace(/\s(http:\/\/)?(\w*\.?\w*\.[a-zA-Z]{2,3}.*?\s)/i, a href='http://$2' target='_blank'$2/a, $url); Same as previously. What about .info, .museum and so on tld ? The filter_var is well suited for this kind of job. Oh, and your regex isn't smart (you use the case insensitivity flag, but seek A-Z characters...) :D -- Mickaël Wolff aka Lupus Michaelis http://lupusmic.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Searching on AlphaNumeric Content Only
Ashley Sheridan a écrit : What's wrong with using the wildcards that are built into most SQL variants? Performance issues. Like is an operator to avoid when possible. -- Mickaël Wolff aka Lupus Michaelis http://lupusmic.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Searching on AlphaNumeric Content Only
On Fri, 2009-09-04 at 17:00 +0200, Lupus Michaelis wrote: Ashley Sheridan a écrit : What's wrong with using the wildcards that are built into most SQL variants? Performance issues. Like is an operator to avoid when possible. -- Mickaël Wolff aka Lupus Michaelis http://lupusmic.org You'll have far greater performance issues if you retrieve all those records and attempt to do the same thing inside of PHP... Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Searching on AlphaNumeric Content Only
sono...@fannullone.us a écrit : Here's an example: let's say there is an itemID of 4D-2448-7PS but someone omits the dashes and searches on 4D24487PS. Is it possible in PHP to have the find be successful, even if the search criteria doesn't exactly match what's stored in the field? I think you don't follow the good path. A good way could be to have a strenger UI management. For exemple, here, you have an ID that is composed about 3 bits. So do the UI present three input fields, or write a smart input (with JS). Of course, in the control side (PHP), you have to check the format of the returned data. Here you can reject the input, or fall through some segment of code that try to interpret the submitted value. But in first time, do it simple and be rough to users. Usability can be improved in a second time. -- Mickaël Wolff aka Lupus Michaelis http://lupusmic.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Searching on AlphaNumeric Content Only
Ashley Sheridan a écrit : You'll have far greater performance issues if you retrieve all those records and attempt to do the same thing inside of PHP... It's why I speak about « avoiding » and not « bannishing ». Like can be usefull, I used to use it. But it is not the a good answer to all problems. The problem with like operator is it can't use the index (or in a very limited way). So I try to warn about it. So said, I never submit an all-retrieving method. I know it isn't the solution too. -- Mickaël Wolff aka Lupus Michaelis http://lupusmic.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] php and ODBC
I am trying to figure out how to use ODBC with PHP. Specifically I need to connect a php script to a SunGard Banner table I know I need to set up some type of DNS connection, but I am not sure what exactly that is. [r...@dev ~]$ odbcinst -j unixODBC 2.2.11 DRIVERS: /etc/odbcinst.ini SYSTEM DATA SOURCES: /etc/odbc.ini USER DATA SOURCES..: /root/.odbc.ini /etc/odbcinst.ini 1 # Example driver definitinions 2 # 3 # 4 5 # Included in the unixODBC package 6 [PostgreSQL] 7 Description = ODBC for PostgreSQL 8 Driver = /usr/lib/libodbcpsql.so 9 Setup = /usr/lib/libodbcpsqlS.so 10 FileUsage = 1 11 12 13 # Driver from the MyODBC package 14 # Setup from the unixODBC package 15 #[MySQL] 16 #Description= ODBC for MySQL 17 #Driver = /usr/lib/libmyodbc.so 18 #Setup = /usr/lib/libodbcmyS.so 19 #FileUsage = 1 Thanks, Marc
[PHP] PHP inserting carriage returns into POST values?
Hey everyone. I ran into a really weird issue that I was hoping I could find some clarification on. In short, I have javascript functions that operate on hidden text values. Those values may be posted, in which case PHP then prints them back to the page via what comes in on $_POST. The weird thing is, I was no longer able to match substrings inside those hidden text values after posting via Javascript. I banged my head over this for a couple hours, until I realized that the string's length was being increased by one after posting (I found this out in javascript). Upon further investigation, I found that all instances of substring\n were being replaced by substring(carriage return)\n after post. For now, I'm simply doing str_replace(chr(13), , $_POST['value']) before re-inserting it into the HTML, but I was wondering why PHP is inserting those extra characters. Thanks! James -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP inserting carriage returns into POST values?
On Fri, Sep 4, 2009 at 3:16 PM, James Colanninoja...@colannino.org wrote: Hey everyone. I ran into a really weird issue that I was hoping I could find some clarification on. In short, I have javascript functions that operate on hidden text values. Those values may be posted, in which case PHP then prints them back to the page via what comes in on $_POST. The weird thing is, I was no longer able to match substrings inside those hidden text values after posting via Javascript. I banged my head over this for a couple hours, until I realized that the string's length was being increased by one after posting (I found this out in javascript). Upon further investigation, I found that all instances of substring\n were being replaced by substring(carriage return)\n after post. For now, I'm simply doing str_replace(chr(13), , $_POST['value']) before re-inserting it into the HTML, but I was wondering why PHP is inserting those extra characters. Thanks! James Are you sure it is PHP? Just a couple ideas... Javascript interpolates \n as a newline character inside both double and single quotes unlike PHP that only interpolates inside double quotes. If the client browser is running under Windows, it may even be possible that the \n is recognized by the browser as a line terminator and converted to the Windows line terminator sequence (\r\n) either inside the form element itself or in the Javascript you are using to post back to the web server. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Include Files in HTML
In my readings, I've run across examples showing include files being called from within the head/head tags, and other examples showing them called within body/body. I've always put them in the header section myself, but I was wondering if one is better than the other, or is it just personal preference? Frank -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Include Files in HTML
From: sono-io at fannullone.us In my readings, I've run across examples showing include files being called from within the head/head tags, and other examples showing them called within body/body. I've always put them in the header section myself, but I was wondering if one is better than the other, or is it just personal preference? Depends on what you are including. The only tags that can be inside the head are base, link, meta, script, style, and title. Everything else is either body or prologue. The full specs can be found at http://www.w3schools.com/tags/default.asp. Bob McConnell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP inserting carriage returns into POST values?
Andrew Ballard wrote: Javascript interpolates \n as a newline character inside both double and single quotes unlike PHP that only interpolates inside double quotes. If the client browser is running under Windows, it may even be possible that the \n is recognized by the browser as a line terminator and converted to the Windows line terminator sequence (\r\n) either inside the form element itself or in the Javascript you are using to post back to the web server. Both the server and the client are Linux machines, so there are no issues with incompatible representations of newline. I only ever place \n's inside double quotes in PHP, and am aware of the fact that I don't have to do that in PHP. For the life of me, I just can't figure out what's happening. Anyway, for now, filtering \r's out in PHP seems to do the trick. James -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Searching on AlphaNumeric Content Only
On Fri, Sep 4, 2009 at 12:02 PM, Lupus Michaelismickael+...@lupusmic.org wrote: Ashley Sheridan a écrit : You'll have far greater performance issues if you retrieve all those records and attempt to do the same thing inside of PHP... It's why I speak about « avoiding » and not « bannishing ». Like can be usefull, I used to use it. But it is not the a good answer to all problems. The problem with like operator is it can't use the index (or in a very limited way). So I try to warn about it. So said, I never submit an all-retrieving method. I know it isn't the solution too. -- Mickaël Wolff aka Lupus Michaelis http://lupusmic.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php So far, in this thread, there've been a few solutions: 1) LIKE in SQL. 2) REGEXP in SQL. 3) PCRE in PHP 4) Other fetch all methods in PHP. The one thing that I'm seeing as a consistent agreement is that the performance hit of whichever of the aforementioned measures is going to be enough to be considering something else. I briefly mentioned - I apologize for the brevity of that email because I was in a hurry - that a legitimate full text search engine is the right solution to this problem. The only problem with deploying a full text search engine is going to be the difficulty in the deployment and perhaps issues if you're on shared hosting (but then again I am of the opinion that those who choose to run with shared hosting dig their own graves in more ways than one). What a full text search engine gives you is flexibility in your searches, such that the initial question, when I read it, I thought Oh, someone will tell him to use Sphinx or Solr as both have special filters for word seperation and would handle this without any special instruction. Instead, this is never even brought up! Why was using a full text search engine to do this sort of thing - not to mention the other benefits that it would bring (responsiveness and flexibility in searching, speed, decreased use of MySQL, etc. etc.) - rejected so offhandedly? I can't actually think of a better way to do this without requiring a whole heap of overhead, either processing or programming. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] script failing at same line
Hi, I have a script that intermittently fails at the same line. I am trying to write some code that will throw an exception after 5 seconds if the command on that line fails and the script freezes. Any ideas? Jim White -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Searching on AlphaNumeric Content Only
Eddie Drapkin wrote: On Fri, Sep 4, 2009 at 12:02 PM, Lupus Michaelismickael+...@lupusmic.org wrote: Ashley Sheridan a écrit : You'll have far greater performance issues if you retrieve all those records and attempt to do the same thing inside of PHP... It's why I speak about « avoiding » and not « bannishing ». Like can be usefull, I used to use it. But it is not the a good answer to all problems. The problem with like operator is it can't use the index (or in a very limited way). So I try to warn about it. So said, I never submit an all-retrieving method. I know it isn't the solution too. -- Mickaël Wolff aka Lupus Michaelis http://lupusmic.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php So far, in this thread, there've been a few solutions: 1) LIKE in SQL. 2) REGEXP in SQL. 3) PCRE in PHP 4) Other fetch all methods in PHP. The one thing that I'm seeing as a consistent agreement is that the performance hit of whichever of the aforementioned measures is going to be enough to be considering something else. I briefly mentioned - I apologize for the brevity of that email because I was in a hurry - that a legitimate full text search engine is the right solution to this problem. The only problem with deploying a full text search engine is going to be the difficulty in the deployment and perhaps issues if you're on shared hosting (but then again I am of the opinion that those who choose to run with shared hosting dig their own graves in more ways than one). What a full text search engine gives you is flexibility in your searches, such that the initial question, when I read it, I thought Oh, someone will tell him to use Sphinx or Solr as both have special filters for word seperation and would handle this without any special instruction. Instead, this is never even brought up! Why was using a full text search engine to do this sort of thing - not to mention the other benefits that it would bring (responsiveness and flexibility in searching, speed, decreased use of MySQL, etc. etc.) - rejected so offhandedly? I can't actually think of a better way to do this without requiring a whole heap of overhead, either processing or programming. I've just sort of stopped in on this thread... but why isn't MySQL's FULLTEXT engine being considered? Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Converting URL's to hyperlinks.
-Original Message- From: Lupus Michaelis [mailto:mickael+...@lupusmic.org] Sent: Friday, September 04, 2009 7:46 AM To: php-general@lists.php.net Subject: Re: [PHP] Converting URL's to hyperlinks. Daevid Vincent a écrit : Maybe I misunderstood the OP, OP ? Original Poster but wouldn't this (or something like it) be Note the something like it. I didn't write his app, just provided a starting point. $url = preg_replace(/(\...@\w+\.[a-za-z]{2,3})/i, a href='mailto:$1'$1/a, $url); This violate the numerous RFC about mail addresses, and some other stuffs. Blah blah blah. I've used this code for about 6 years now and have yet to find emails that it didn't work for. If someone has some funky (whacky) RFC extremity, then so be it. That's their problem. Most people have NORMAL emails that follow the above. But you are correct, I have revised it to be a little more forgiving of some allowed characters... preg_replace(/([\w\.\-...@[\w\.\-_]+\.\w{2,6})/i, $url = preg_replace(/\s(http:\/\/)?(\w*\.?\w*\.[a-zA-Z]{2,3}.*?\s)/i, a href='http://$2' target='_blank'$2/a, $url); Same as previously. What about .info, .museum and so on tld ? What about them? It's going to depend on how/where you use this. In my case, 2 and 3 letter domains are all I encounter. It's trivial to make it {2,6} if you really are going to encounter a .museum domain. DOUBTFUL, but sure, I'll concede the three extra letters. ;-) However, you point out a few edge cases and so I optimized mine and now use this one: http://snipplr.com/view/2371/regex-regular-expression-to-match-a-url/ Oh, and your regex isn't smart (you use the case insensitivity flag, but seek A-Z characters...) :D Noted. Thanks for the optimization. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Converting URL's to hyperlinks.
2009/9/4 Daevid Vincent dae...@daevid.com -Original Message- From: Lupus Michaelis [mailto:mickael+...@lupusmic.orgmickael%2b...@lupusmic.org ] Sent: Friday, September 04, 2009 7:46 AM To: php-general@lists.php.net Subject: Re: [PHP] Converting URL's to hyperlinks. Daevid Vincent a écrit : Maybe I misunderstood the OP, OP ? Original Poster but wouldn't this (or something like it) be Note the something like it. I didn't write his app, just provided a starting point. $url = preg_replace(/(\...@\w+\.[a-za-z]{2,3})/i, a href='mailto:$1'$1/a, $url); This violate the numerous RFC about mail addresses, and some other stuffs. Blah blah blah. I've used this code for about 6 years now and have yet to find emails that it didn't work for. If someone has some funky (whacky) RFC extremity, then so be it. That's their problem. Most people have NORMAL emails that follow the above. But you are correct, I have revised it to be a little more forgiving of some allowed characters... preg_replace(/([\w\.\-...@[\w\.\-_]+\.\w{2,6})/i, $url = preg_replace(/\s(http:\/\/)?(\w*\.?\w*\.[a-zA-Z]{2,3}.*?\s)/i, a href='http://$2' target='_blank'$2/a, $url); Same as previously. What about .info, .museum and so on tld ? What about them? It's going to depend on how/where you use this. In my case, 2 and 3 letter domains are all I encounter. It's trivial to make it {2,6} if you really are going to encounter a .museum domain. DOUBTFUL, but sure, I'll concede the three extra letters. ;-) However, you point out a few edge cases and so I optimized mine and now use this one: http://snipplr.com/view/2371/regex-regular-expression-to-match-a-url/ Oh, and your regex isn't smart (you use the case insensitivity flag, but seek A-Z characters...) :D Noted. Thanks for the optimization. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Thanks for posting that! Will be really handy for me!
RE: [PHP] script failing at same line
[snip] I have a script that intermittently fails at the same line. I am trying to write some code that will throw an exception after 5 seconds if the command on that line fails and the script freezes. Any ideas? [/snip] I have lots of ideas! But those really won't help you :) We need to see the code at that line and be told what is being done in order to make a reasonable guess. My bet is that the data being fed to the script has a character that is not expected or something. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] script failing at same line
$map = ms_newMapObj($mapfile); The command creates a new mapscript object. Jay Blanchard wrote: [snip] I have a script that intermittently fails at the same line. I am trying to write some code that will throw an exception after 5 seconds if the command on that line fails and the script freezes. Any ideas? [/snip] I have lots of ideas! But those really won't help you :) We need to see the code at that line and be told what is being done in order to make a reasonable guess. My bet is that the data being fed to the script has a character that is not expected or something. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] script failing at same line
$map = ms_newMapObj($mapfile); The command creates a new mapscript object. And PHP is hanging somewhere inside that constructor? Is this in a web context or a command-line context? Or both?
RE: [PHP] Include Files in HTML
Bob McConnell wrote: From: sono-io at fannullone.us In my readings, I've run across examples showing include files being called from within the head/head tags, and other examples showing them called within body/body. I've always put them in the header section myself, but I was wondering if one is better than the other, or is it just personal preference? Depends on what you are including. The only tags that can be inside the head are base, link, meta, script, style, and title. Everything else is either body or prologue. The full specs can be found at http://www.w3schools.com/tags/default.asp. Bob McConnell Sure enough. What the OP might not have realized: In the end, what PHP evaluates to, is a stream of html, script, css etc text/data, which is sent to the browser. PHP's include( file ) statement inserts the content of file here-and-now. You can even put the include statement within a for loop in order to include something multiple times... In that sense it is more like a /function/ and really different from cpp's #include /directive/. file can contain PHP code, which is evaluated as if it was here-and-now in the including PHP file; it can contain text/data, which is appended to the text/data stream being produced. All in all, to PHP the spot of file inclusion is not interesting, as long as the resulting PHP code and/or stream data is meaningful. Now back to you, Bob :-) Regards, Joost. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] script failing at same line
It's a web app that draws maps in a browser. Sometime it will generate a seg fault. The command should not take long, so if there is some script construct that will throw an exception after a few seconds if the command has not completed I could signal the user that the map will not draw and to reload the page. Jim Ben Dunlap wrote: $map = ms_newMapObj($mapfile); The command creates a new mapscript object. And PHP is hanging somewhere inside that constructor? Is this in a web context or a command-line context? Or both? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] accessing variable from inside a class
Hi, How do i access a variable from inside a class? ex. I want to use $template_dir inside Template. $template_dir = 'templates/'; class templateParser { var $output; function templateParser($templateFile='default_template.htm') { (file_exists($template_dir.$templateFile)) ? $this-output=file_get_contents($template_dir.$templateFile) : die('Error:Template file '.$template_dir.$templateFile.' not found'); } } I run Fedora 10, apache 2.2.11 and php 5.2.9. I get an error saying that $template_dir is undefined. Regards Lars Nielsen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP6 Stable Release Schedule
Hi, Does anyone know when the stable release of PHP6 be ready for download? I hear there's a lot of goodies in version 6 including built-in Caching. Yum. Also, will PHP ever implement the Strict mode similar to Perl's 'using Strict'? Thanks, Bobby
Re: [PHP] accessing variable from inside a class
Lars Nielsen wrote: Hi, How do i access a variable from inside a class? Add the following statement: global $template_dir; James -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP6 Stable Release Schedule
On Fri, Sep 4, 2009 at 17:42, Bobby Pejmanbpej...@gmail.com wrote: Hi, Does anyone know when the stable release of PHP6 be ready for download? I hear there's a lot of goodies in version 6 including built-in Caching. Yum. Also, will PHP ever implement the Strict mode similar to Perl's 'using Strict'? There is no date scheduled - or even well-estimated - for a stable version of PHP6. Best guesses are that, while it's not impossible to say within the next year, mid- to late-2010 or even 2011 is a prudent expectation. -- /Daniel P. Brown daniel.br...@parasane.net || danbr...@php.net http://www.parasane.net/ || http://www.pilotpig.net/ Check out our great hosting and dedicated server deals at http://twitter.com/pilotpig -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how to strip empty lines out of a txt using preg_replace()
Sam Stelfox wrote: The following snippet is untested and using Ash's regex (it is accurate \s matches any white space). $content is what is getting stripped of the new lines and $filtered is the cleansed output. See if that does the trick for you. $lines = str_split(PHP_EOL, $content); $filtered = ''; foreach ($lines as $line) { if (!preg_match('^\s*$', $line)) { // Splitting on the PHP_EOL characters cause it to be removed be sure to put it back $filtered .= $line . PHP_EOL; } } That isn't going to work. You missed your delimiters in the first arg for preg_match(). It requires beginning and ending delimiters around the regex. I would try this $lines = preg_split('|[\n\r]|', $content); $filtered = ''; foreach ( $lines as $line ) { $txt = trim( $line ); if ( ! empty( $txt ) ) { $filtered .= $line; } } It is much more intense to do the preg_match inside a loop. You should only do it once, then use less intense function calls inside the loop. warning: completely untested... have no example input you are using... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP inserting carriage returns into POST values?
On Fri, 04 Sep 2009 12:16:47 -0700, James Colannino wrote: Hey everyone. I ran into a really weird issue that I was hoping I could find some clarification on. In short, I have javascript functions that operate on hidden text values. Those values may be posted, in which case PHP then prints them back to the page via what comes in on $_POST. The weird thing is, I was no longer able to match substrings inside those hidden text values after posting via Javascript. I banged my head over this for a couple hours, until I realized that the string's length was being increased by one after posting (I found this out in javascript). Upon further investigation, I found that all instances of substring\n were being replaced by substring(carriage return)\n after post. It may be the browser that is converting those line breaks. From the HTML spec.: http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1: application/x-www-form-urlencoded ... Line breaks are represented as CR LF pairs (i.e., `%0D%0A'). http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2: multipart/form-data ... CR LF (i.e., `%0D%0A') is used to separate lines of data. /Nisse -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Include Files in HTML
On Sep 4, 2009, at 1:05 PM, Bob McConnell wrote: Depends on what you are including. The only tags that can be inside the head are base, link, meta, script, style, and title. Everything else is either body or prologue. I meant PHP includes like this one: ?php @include_once(/home/passwords/login.php); ? Frank -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP inserting carriage returns into POST values?
On Fri, Sep 04, 2009 at 12:16:47PM -0700, James Colannino wrote: Hey everyone. I ran into a really weird issue that I was hoping I could find some clarification on. In short, I have javascript functions that operate on hidden text values. Those values may be posted, in which case PHP then prints them back to the page via what comes in on $_POST. The weird thing is, I was no longer able to match substrings inside those hidden text values after posting via Javascript. I banged my head over this for a couple hours, until I realized that the string's length was being increased by one after posting (I found this out in javascript). Upon further investigation, I found that all instances of substring\n were being replaced by substring(carriage return)\n after post. For now, I'm simply doing str_replace(chr(13), , $_POST['value']) before re-inserting it into the HTML, but I was wondering why PHP is inserting those extra characters. I don't know that this will help, but maybe it will provide a clue. A textarea field will insert CRLF in its posted contents. You might expect this to be governed by the platform the browser is running on, but no. It inserts CRLF anyway. Like I said, just a clue. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: accessing variable from inside a class
Lars Nielsen wrote: Hi, How do i access a variable from inside a class? ex. I want to use $template_dir inside Template. $template_dir = 'templates/'; class templateParser { var $output; function templateParser($templateFile='default_template.htm') { (file_exists($template_dir.$templateFile)) ? $this-output=file_get_contents($template_dir.$templateFile) : die('Error:Template file '.$template_dir.$templateFile.' not found'); } } I run Fedora 10, apache 2.2.11 and php 5.2.9. I get an error saying that $template_dir is undefined. Regards Lars Nielsen Well you have to access it as a global by either declaring it global in the method (global $template_dir;) or by the superglobal $GLOBALS['template_dir']. However this is probably not the preferred way to do it. I would either define it as a constant define('TEMPLATE_DIR', 'templates/') or you could pass $template_dir into the class constructor and have it set as a class var, but I prefer the constant. -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] accessing variable from inside a class
I cant get it to work. I will use a configuration class instead. function templateParser($templateFile='default_template.htm') { $c = new config(); (file_exists($c-template_dir.$templateFile)) ? $this-output=file_get_contents($c-template_dir.$templateFile) : die('Error:Template file '.$template_dir.$templateFile.' not found'); } /Lars fre, 04 09 2009 kl. 14:49 -0700, skrev James Colannino: Lars Nielsen wrote: Hi, How do i access a variable from inside a class? Add the following statement: global $template_dir; James -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Searching on AlphaNumeric Content Only
- Original Message From: Robert Cummings rob...@interjinn.com To: Eddie Drapkin oorza...@gmail.com Cc: Lupus Michaelis mickael+...@lupusmic.org; php-general@lists.php.net Sent: Friday, September 4, 2009 1:36:08 PM Subject: Re: [PHP] Searching on AlphaNumeric Content Only Eddie Drapkin wrote: On Fri, Sep 4, 2009 at 12:02 PM, Lupus Michaeliswrote: Ashley Sheridan a écrit : You'll have far greater performance issues if you retrieve all those records and attempt to do the same thing inside of PHP... It's why I speak about « avoiding » and not « bannishing ». Like can be usefull, I used to use it. But it is not the a good answer to all problems. The problem with like operator is it can't use the index (or in a very limited way). So I try to warn about it. So said, I never submit an all-retrieving method. I know it isn't the solution too. -- Mickaël Wolff aka Lupus Michaelis http://lupusmic.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php So far, in this thread, there've been a few solutions: 1) LIKE in SQL. 2) REGEXP in SQL. 3) PCRE in PHP 4) Other fetch all methods in PHP. The one thing that I'm seeing as a consistent agreement is that the performance hit of whichever of the aforementioned measures is going to be enough to be considering something else. I briefly mentioned - I apologize for the brevity of that email because I was in a hurry - that a legitimate full text search engine is the right solution to this problem. The only problem with deploying a full text search engine is going to be the difficulty in the deployment and perhaps issues if you're on shared hosting (but then again I am of the opinion that those who choose to run with shared hosting dig their own graves in more ways than one). What a full text search engine gives you is flexibility in your searches, such that the initial question, when I read it, I thought Oh, someone will tell him to use Sphinx or Solr as both have special filters for word seperation and would handle this without any special instruction. Instead, this is never even brought up! Why was using a full text search engine to do this sort of thing - not to mention the other benefits that it would bring (responsiveness and flexibility in searching, speed, decreased use of MySQL, etc. etc.) - rejected so offhandedly? I can't actually think of a better way to do this without requiring a whole heap of overhead, either processing or programming. I've just sort of stopped in on this thread... but why isn't MySQL's FULLTEXT engine being considered? If I remember correctly, it's only on available on MyISAM table type. I don't think the OP mentioned that he's using MyISAM or MySQL for that matter. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- 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] Searching on AlphaNumeric Content Only
On Fri, Sep 04, 2009 at 04:22:18PM -0400, Eddie Drapkin wrote: On Fri, Sep 4, 2009 at 12:02 PM, Lupus Michaelismickael+...@lupusmic.org wrote: if you're on shared hosting (but then again I am of the opinion that those who choose to run with shared hosting dig their own graves in more ways than one). Any time you or someone else would like to backstop me in setting up a dedicated server on rackspace or somewhere else, for free or really cheap, you let me know! Otherwise, those of us with less than complete expertise in server setup are stuck with shared hosting. ;-} Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: PHP inserting carriage returns into POST values?
Nisse Engström wrote: It may be the browser that is converting those line breaks. Ah. That's probably it then. I didn't realize that was a part of the HTML standard. Thanks! James -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] script failing at same line
On Fri, Sep 4, 2009 at 2:38 PM, jim white jbw2...@earthlink.net wrote: It's a web app that draws maps in a browser. Sometime it will generate a seg fault. The command should not take long, so if there is some script construct that will throw an exception after a few seconds if the command has not completed I could signal the user that the map will not draw and to reload the page. There's a pecl extension called Libevent that can apparently trigger an action to occur after a certain amount of time has elapsed: http://us3.php.net/manual/en/ref.libevent.php I've not used it and have no idea how mature or reliable it is. I'm also wondering whether any solution will work that relies on the same script that's about to trigger a segfault. I think I'd be inclined to build an XHR-based monitor to run in the user's browser. Even simpler would be to start the map-building process asynchronously with XHR and then just alert the user, or automatically refresh the browser, if a certain amount of time elapses before you get a response from the map-building script. But I don't know how much you'd have to alter your existing client-side code to use the latter method. Either way it's creeping away from PHP so maybe I should leave it at that. Ben
Re: [PHP] Include Files in HTML
- Original Message From: sono...@fannullone.us sono...@fannullone.us To: PHP General List php-general@lists.php.net Sent: Friday, September 4, 2009 12:57:08 PM Subject: [PHP] Include Files in HTML In my readings, I've run across examples showing include files being called from within the tags, and other examples showing them called within . I've always put them in the header section myself, but I was wondering if one is better than the other, or is it just personal preference? Frank --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Depends on your application design and/or your desired result. If you design your application to do all processing before output is sent starting with html, then all your includes goes before html. If you want to have the modular approach of including css js files inside the head element, you don't have to worry about going back to changing every single output file when you decide the change your layout or javascript framework. It also makes your code page a bit cleaner when you do use include in the head. If you want to make use of chunked encoding, you can including the rest within the body. Thus, include everything before html gives you a slight pause 'waiting for reply...' in the status bar before the client even begin to download anything. When includes are scattered all over, server processes some sends the web browser info, here go fetch some more (css, js, images) until the the last buffered output is sent /html (that is if your page is compliant ;) Regards, Tommy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Include Files in HTML
- Original Message From: Tommy Pham tommy...@yahoo.com To: php-general@lists.php.net Sent: Friday, September 4, 2009 4:11:31 PM Subject: Re: [PHP] Include Files in HTML - Original Message From: sono...@fannullone.us To: PHP General List Sent: Friday, September 4, 2009 12:57:08 PM Subject: [PHP] Include Files in HTML In my readings, I've run across examples showing include files being called from within the tags, and other examples showing them called within . I've always put them in the header section myself, but I was wondering if one is better than the other, or is it just personal preference? Frank --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Depends on your application design and/or your desired result. If you design your application to do all processing before output is sent starting with , then all your includes goes before . If you want to have the modular approach of including css js files inside the element, you don't have to worry about going back to changing every single output file when you decide the change your layout or javascript framework. It also makes your code page a bit cleaner when you do use include in the . If you want to make use of chunked encoding, you can including the rest within the . Thus, include everything before gives you a slight pause 'waiting for reply...' in the status bar before the client even begin to download anything. When includes are scattered all over, server processes some sends the web browser info, here go fetch some more (css, js, images) until the the last buffered output is sent (that is if your page is compliant ;) Regards, Tommy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Forgot to mention a few things, if your app is sophisticated enough to require header settings (content-type, etc), those include have to go before the buffered output is sent. Also, you want to make use of chunked encoding, you cannot use/specify content-length in the header. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Include Files in HTML
On Sep 4, 2009, at 5:03 PM, sono...@fannullone.us wrote: Depends on what you are including. The only tags that can be inside the head are base, link, meta, script, style, and title. Everything else is either body or prologue. I meant PHP includes like this one: ?php @include_once(/home/passwords/login.php); ? We know what you mean. Read the responses more carefully, as they are telling you what you need to know. For simplification: The INCLUDE commands put the contents of the INCLUDed file into this file, just as if as you had typed it in there. Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] script failing at same line
Hi, Thanks I'll look at libevent. I have also been thinking about using an XHR approach, but wonder how passing PHP references works with javascript. Jim Ben Dunlap wrote: On Fri, Sep 4, 2009 at 2:38 PM, jim white jbw2...@earthlink.net mailto:jbw2...@earthlink.net wrote: It's a web app that draws maps in a browser. Sometime it will generate a seg fault. The command should not take long, so if there is some script construct that will throw an exception after a few seconds if the command has not completed I could signal the user that the map will not draw and to reload the page. There's a pecl extension called Libevent that can apparently trigger an action to occur after a certain amount of time has elapsed: http://us3.php.net/manual/en/ref.libevent.php I've not used it and have no idea how mature or reliable it is. I'm also wondering whether any solution will work that relies on the same script that's about to trigger a segfault. I think I'd be inclined to build an XHR-based monitor to run in the user's browser. Even simpler would be to start the map-building process asynchronously with XHR and then just alert the user, or automatically refresh the browser, if a certain amount of time elapses before you get a response from the map-building script. But I don't know how much you'd have to alter your existing client-side code to use the latter method. Either way it's creeping away from PHP so maybe I should leave it at that. Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Searching on AlphaNumeric Content Only
Paul M Foster wrote: On Fri, Sep 04, 2009 at 04:22:18PM -0400, Eddie Drapkin wrote: On Fri, Sep 4, 2009 at 12:02 PM, Lupus Michaelismickael+...@lupusmic.org wrote: if you're on shared hosting (but then again I am of the opinion that those who choose to run with shared hosting dig their own graves in more ways than one). Any time you or someone else would like to backstop me in setting up a dedicated server on rackspace or somewhere else, for free or really cheap, you let me know! Otherwise, those of us with less than complete expertise in server setup are stuck with shared hosting. ;-} For a few hundred bucks a year you can get a VPS (Virtual Private Server), which gives you root access. once you get a couple of clients on it, it will pay for itself year after year. If you have clients that don't use much resources, you can put a few on and even make a profit on the hosting alone. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: how to strip empty lines out of a txt using preg_replace()
On Fri, 4 Sep 2009 14:58:55 +0200, ralph_def...@yahoo.de (Ralph Deffke) wrote: Hi all, I'm a bit under stress, maybe somebody knows the regex on a snap. using PHP_EOL would be great. Here is a function which works for files pasted from browser screens: function clean_up($dirty_file) { $contents = file_get_contents ($dirty_file); if ($contents) { $c_array = explode (\n, $contents); $n = count($c_array); $i = 0; $j = 0; while ($i $n) { $line = trim($c_array[$i]); if ($line != '') { $d_array[$j++] = $c_array[$i]; } ++$i; } $clean = implode (\n,$d_array); $data_file = file_put_contents($data_file, $clean); } } The virtue of this is you don't have to know, or care, what characters are on the blank lines. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Searching on AlphaNumeric Content Only
On Fri, Sep 04, 2009 at 08:15:41PM -0400, Robert Cummings wrote: Paul M Foster wrote: On Fri, Sep 04, 2009 at 04:22:18PM -0400, Eddie Drapkin wrote: On Fri, Sep 4, 2009 at 12:02 PM, Lupus Michaelismickael+...@lupusmic.org wrote: if you're on shared hosting (but then again I am of the opinion that those who choose to run with shared hosting dig their own graves in more ways than one). Any time you or someone else would like to backstop me in setting up a dedicated server on rackspace or somewhere else, for free or really cheap, you let me know! Otherwise, those of us with less than complete expertise in server setup are stuck with shared hosting. ;-} For a few hundred bucks a year you can get a VPS (Virtual Private Server), which gives you root access. once you get a couple of clients on it, it will pay for itself year after year. If you have clients that don't use much resources, you can put a few on and even make a profit on the hosting alone. Oh sure. Well aware of it. The problem is not finding a VPS or working with root access or anything like that. The problem is expertise. POP3, SMTP, SSH, HTTP, DNS, firewall security while still allowing access to outward facing servers, etc. It's more expertise than most people have, including me. The servers I run are internal and don't have to deal with the rigors of the internet, and only serve a couple of people. Setting up multiple domains under an Apache server is black magic to me, for instance. And then there's backups, and what-do-I-do-if-the-server-fails, etc. Sheesh. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Searching on AlphaNumeric Content Only
- Original Message From: Paul M Foster pa...@quillandmouse.com To: php-general@lists.php.net Sent: Friday, September 4, 2009 9:15:08 PM Subject: Re: [PHP] Searching on AlphaNumeric Content Only On Fri, Sep 04, 2009 at 08:15:41PM -0400, Robert Cummings wrote: Paul M Foster wrote: On Fri, Sep 04, 2009 at 04:22:18PM -0400, Eddie Drapkin wrote: On Fri, Sep 4, 2009 at 12:02 PM, Lupus Michaeliswrote: if you're on shared hosting (but then again I am of the opinion that those who choose to run with shared hosting dig their own graves in more ways than one). Any time you or someone else would like to backstop me in setting up a dedicated server on rackspace or somewhere else, for free or really cheap, you let me know! Otherwise, those of us with less than complete expertise in server setup are stuck with shared hosting. ;-} For a few hundred bucks a year you can get a VPS (Virtual Private Server), which gives you root access. once you get a couple of clients on it, it will pay for itself year after year. If you have clients that don't use much resources, you can put a few on and even make a profit on the hosting alone. Oh sure. Well aware of it. The problem is not finding a VPS or working with root access or anything like that. The problem is expertise. POP3, SMTP, SSH, HTTP, DNS, firewall security while still allowing access to outward facing servers, etc. It's more expertise than most people have, including me. The servers I run are internal and don't have to deal with the rigors of the internet, and only serve a couple of people. Setting up multiple domains under an Apache server is black magic to me, for instance. And then there's backups, and what-do-I-do-if-the-server-fails, etc. Sheesh. I stand corrected. You paid for peace of mind :D Paul -- Paul M. Foster -- 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