php-general Digest 19 Dec 2008 00:06:10 -0000 Issue 5853

Topics (messages 284780 through 284809):

Re: fread question
        284780 by: MikeP
        284781 by: MikeP
        284786 by: Boyd, Todd M.
        284788 by: Boyd, Todd M.
        284791 by: ceo.l-i-e.com
        284795 by: MikeP

Re: Phpmyadmin password
        284782 by: Jochem Maas
        284802 by: VamVan

Regex Problem
        284783 by: MikeP
        284785 by: Boyd, Todd M.
        284799 by: MikeP

php 5.2.8 error_log - relative paths
        284784 by: Andre Hübner

Re: Read/decode barcodes from an image
        284787 by: Al
        284793 by: ceo.l-i-e.com
        284796 by: Boyd, Todd M.
        284797 by: ceo.l-i-e.com

Re: runtime access to static variable
        284789 by: ceo.l-i-e.com

still can't get a login with session working ... is there another way to mask 
the url parameter?
        284790 by: Terion Miller
        284794 by: Ólafur Waage

Re: Php question from Newsgroup
        284792 by: Boyd, Todd M.
        284798 by: MikeP

CLI in background on windows
        284800 by: Fanda
        284801 by: Boyd, Todd M.
        284808 by: Fanda

Re: Good PHP book?
        284803 by: franzemmanuel

Variable Scope problem passing function parameters
        284804 by: Jim McIntyre
        284805 by: metastable
        284806 by: Jim McIntyre

SOLVED Re: [PHP] Variable Scope problem passing function parameters
        284807 by: Jim McIntyre

utf8 php howto?
        284809 by: Daniel Kolbo

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
But this one is ON
magic_quotes_gpc
"Robert Cummings" <[email protected]> wrote in message 
news:1229567238.8302.35.ca...@localhost...
> On Wed, 2008-12-17 at 19:54 -0500, MikeP wrote:
>> Hello,
>> I have been trying to use fread to open a file, but it always escapes
>> special characters.
>> How do I open  afile without it modifying my original file:
>>
>> $_POST[$fname] = fread($fileHandle, $_POST[$fname.'_size']);
>> I use this and get slashes everywhere.This kills my REGex that gets coded
>> next.
>
> Check this magically shitty setting in your php.ini:
>
>    magic_quotes_runtime
>
> It should be off unless someone with less brains than a turd got a hold
> of your ini file.
>
> Cheers,
> Rob.
> -- 
> http://www.interjinn.com
> Application and Templating Framework for PHP
> 



--- End Message ---
--- Begin Message ---
Still having problems:
magic_quotes_runtime is off
BUT
magic_quotes_gpc is on
I cant change them myself so I tried
stripslashes
That doesnt work though:

$_POST[$fname] = fread($fileHandle, $_POST[$fname.'_size']);
    $test=$_POST[$fname];
    $test3=stripslashes($test);

$test3 and $test are the same.

Any other Ideas?

Thanks
mike



"Robert Cummings" <[email protected]> wrote in message 
news:1229567238.8302.35.ca...@localhost...
> On Wed, 2008-12-17 at 19:54 -0500, MikeP wrote:
>> Hello,
>> I have been trying to use fread to open a file, but it always escapes
>> special characters.
>> How do I open  afile without it modifying my original file:
>>
>> $_POST[$fname] = fread($fileHandle, $_POST[$fname.'_size']);
>> I use this and get slashes everywhere.This kills my REGex that gets coded
>> next.
>
> Check this magically shitty setting in your php.ini:
>
>    magic_quotes_runtime
>
> It should be off unless someone with less brains than a turd got a hold
> of your ini file.
>
> Cheers,
> Rob.
> -- 
> http://www.interjinn.com
> Application and Templating Framework for PHP
> 



--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: MikeP [mailto:[email protected]]
> Sent: Thursday, December 18, 2008 7:33 AM
> To: [email protected]
> Subject: Re: [PHP] fread question
> 
> Still having problems:
> magic_quotes_runtime is off
> BUT
> magic_quotes_gpc is on
> I cant change them myself so I tried
> stripslashes
> That doesnt work though:
> 
> $_POST[$fname] = fread($fileHandle, $_POST[$fname.'_size']);
>     $test=$_POST[$fname];
>     $test3=stripslashes($test);
> 
> $test3 and $test are the same.
> 
> Any other Ideas?
> 
> "Robert Cummings" <[email protected]> wrote in message
> news:1229567238.8302.35.ca...@localhost...
> > On Wed, 2008-12-17 at 19:54 -0500, MikeP wrote:
> >> Hello,
> >> I have been trying to use fread to open a file, but it always
> escapes
> >> special characters.
> >> How do I open  afile without it modifying my original file:
> >>
> >> $_POST[$fname] = fread($fileHandle, $_POST[$fname.'_size']);
> >> I use this and get slashes everywhere.This kills my REGex that gets
> coded
> >> next.
> >
> > Check this magically shitty setting in your php.ini:
> >
> >    magic_quotes_runtime
> >
> > It should be off unless someone with less brains than a turd got a
> hold
> > of your ini file.

The PHP site's page on ini_set() [1] talks a bit about how to set that
particular option in an .htaccess file:

        set PHP_INI_PERDIR settings in a .htaccess file with 'php_flag'
like this:

        php_flag register_globals off
        php_flag magic_quotes_gpc on

If you can get at your .htaccess, maybe you could do it that way (since
I don't believe you can change magic_quotes_gpc using ini_set() or
similar methods).

HTH,


// Todd

--- End Message ---
--- Begin Message ---
Hah! Forgot to add the link:

        1. http://php.net/ini_set

How would you guys have ever figured out that was the page on PHP's
website you need to visit in order to view information about the
ini_set() function?!

;)


// Todd

--- End Message ---
--- Begin Message ---
PHP does *not* do the addslashes on $_POST when you cram something into it in 
your PHP code.



It does it during the process of auto-filling up $_POST.



So either:

A) you have magic_quotes_runtime turned on LOCALLY. Use phpinfo() to see.

B) you actually managed to put the backslashes into your text file.



PS

You really shouldn't be cramming data into $_POST, imho.

Too confusing for later development/maintenance.

$_POST should be "read only"

Copy the parts of $_POST you want into something else, and add in your file 
contents as well.



--- End Message ---
--- Begin Message ---
 you have magic_quotes_runtime turned on LOCALLY. Use phpinfo() to see.
NOmagic_quotes_runtime Off

 you actually managed to put the backslashes into your text file.
NO
<td><input name="letter" type="file" id="letter" size="50" maxlength="255" 
/>
.
.
.
.
<?php
process_uploaded_file('letter');
function process_uploaded_file($fname) {
    // Assumes set of $_POST variables in the form: name, name_fname, 
name_size, name_type
    $_POST[$fname.'_fname'] = $_FILES[$fname]['name'];
    $_POST[$fname.'_size'] = $_FILES[$fname]['size'];
    $_POST[$fname.'_type'] = $_FILES[$fname]['type'];
    $_POST[$fname.'_fname'] = strtr($_POST[$fname.'_fname'],' 
%&*;:"{}[]|\<>,/()%...@!','________________________'); //fix special chars in 
name
    $_POST[$fname.'_fname'] = strtr($_POST[$fname.'_fname'],"'","_");
    $fileHandle = fopen($_FILES[$fname]['tmp_name'], "r");
    $_POST[$fname] =stripslashes(fread($fileHandle, 
$_POST[$fname.'_size']));


Neither

<[email protected]> wrote in message 
news:[email protected]...
>
> PHP does *not* do the addslashes on $_POST when you cram something into it 
> in your PHP code.
>
> It does it during the process of auto-filling up $_POST.
>
> So either:
> A) you have magic_quotes_runtime turned on LOCALLY. Use phpinfo() to see.
> B) you actually managed to put the backslashes into your text file.
>
> PS
> You really shouldn't be cramming data into $_POST, imho.
> Too confusing for later development/maintenance.
> $_POST should be "read only"
> Copy the parts of $_POST you want into something else, and add in your 
> file contents as well.
> 



--- End Message ---
--- Begin Message ---
VamVan schreef:
..

May be u can do a bowl
> fish encryption 

...

> Thanks,
> V

LOL. 'bowl fish' ... 'fish bowl' ... I guess you meant to write 'blow' :-)

--- End Message ---
--- Begin Message ---
Yeah true thanks for pointing out. Thats what I meant !!! :)

Blowfish (http://en.wikipedia.org/wiki/Blowfish_(cipher))

On Thu, Dec 18, 2008 at 6:11 AM, Jochem Maas <[email protected]> wrote:

> VamVan schreef:
> ..
>
> May be u can do a bowl
> > fish encryption
>
> ...
>
> > Thanks,
> > V
>
> LOL. 'bowl fish' ... 'fish bowl' ... I guess you meant to write 'blow' :-)
>

--- End Message ---
--- Begin Message ---
Hello,
I have  a quirky behavior I'm trying to resolve.
I have a REGEX that will find a function definition in a php file:
.....function InsertQuery($table,$fields,$values).....
the REGEX is:
$regex='/function [a-z]* *([$a-zA-Z]*)/';
the problem is that:
1. a slash is automattically put in front of the $. This is good but I dont 
know how it gets there.
2.a slash is NOT put in front of the parenthesis. Thats bad
3. If I try to escape the parenthesis with a \ , I get \\.
Help 



--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: MikeP [mailto:[email protected]]
> Sent: Thursday, December 18, 2008 8:43 AM
> To: [email protected]
> Subject: [PHP] Regex Problem
> 
> Hello,
> I have  a quirky behavior I'm trying to resolve.
> I have a REGEX that will find a function definition in a php file:
> .....function InsertQuery($table,$fields,$values).....
> the REGEX is:
> $regex='/function [a-z]* *([$a-zA-Z]*)/';
> the problem is that:
> 1. a slash is automattically put in front of the $. This is good but I
> dont
> know how it gets there.
> 2.a slash is NOT put in front of the parenthesis. Thats bad
> 3. If I try to escape the parenthesis with a \ , I get \\.
> Help

Mike,

Certain characters are considered "special" in RegEx. The $ means "end
of the line," so it must be escaped to avoid confusing its meaning. I
was not sure it had to be escaped within a character set [], but that
may very well be the case. Try this:

$regex = '/function\s+[-_a-z0-9]+\s*\((\s*\$?[-_a-z0-9]+\s*,?)*\s*\)/i';

The word "function" is followed by 1 or more spaces (or tabs). The
function name [-_a-z0-9] can be a combination of alpha-numeric
characters, underscore, and dash. Then, there is optional whitespace
between the name of the function and its parameters. The opening
parenthesis "(" for parameters has been escaped (as has the closing
parenthesis). Then, in a repeatable capture group, the parameters can be
grabbed: Indefinite whitespace, an optional $ (because maybe you're not
using a variable, eh?), one or more alpha-numeric, underscore, or dash
characters, followed by indefinite whitespace and an optional comma (if
there are more arguments). After any number of instances of the capture
group, the regex continues by looking for indefinite whitespace followed
by the closing parenthesis for the function text. The "i" switch at the
end simply means that this regex pattern will be treated as
case-insensitive ('APPLE' == 'apple').

If you're not worried about actually splitting up the function
parameters into capture groups, then you can just use a look-ahead to
ensure that you grab everything up till the LAST parenthesis on the
line.

$regex = '/function\s+[-_a-z0-9]+\s*\(.*?\)(?=.*\)[^)]*)/i';

That one probably needs to be tweaked a bit in order to actually grab
the last parenthesis (instead of just checking for its existence). If
you're willing to trust the text you'll be searching through, you can
probably avoid that "last parenthesis" rule altogether, and make a lazy
regex:

$regex = '/function\s+[-_a-z0-9]+\s*\(.*?/i';

Once you get to the opening parenthesis for the function parameters,
that last regex assumes that the rest of the line will also include that
function declaration, and just grabs everything left. If you are using a
regex setup to where the dot marker can also consume newline or carriage
return characters, just throw a "$" at the end of the regex (before the
flags part "/i") in order to tell it just to grab characters until it
reaches the end of the line:

$regex = '/function\s+[-_a-z0-9]+\s*\(.*?$/i';

These are all untested, but hopefully I've given you a nudge in the
right direction. If you are still getting strange behavior out of your
PCRE engine, then perhaps you have a different version installed than
what I'm used to--all of the above should work (perhaps with some very
minor changes) in PHP.

HTH,


// Todd

--- End Message ---
--- Begin Message ---
""Boyd, Todd M."" <[email protected]> wrote in message 
news:[email protected]...
> -----Original Message-----
> From: MikeP [mailto:[email protected]]
> Sent: Thursday, December 18, 2008 8:43 AM
> To: [email protected]
> Subject: [PHP] Regex Problem
>
> Hello,
> I have  a quirky behavior I'm trying to resolve.
> I have a REGEX that will find a function definition in a php file:
> .....function InsertQuery($table,$fields,$values).....
> the REGEX is:
> $regex='/function [a-z]* *([$a-zA-Z]*)/';
> the problem is that:
> 1. a slash is automattically put in front of the $. This is good but I
> dont
> know how it gets there.
> 2.a slash is NOT put in front of the parenthesis. Thats bad
> 3. If I try to escape the parenthesis with a \ , I get \\.
> Help

Mike,

Certain characters are considered "special" in RegEx. The $ means "end
of the line," so it must be escaped to avoid confusing its meaning. I
was not sure it had to be escaped within a character set [], but that
may very well be the case. Try this:

$regex = '/function\s+[-_a-z0-9]+\s*\((\s*\$?[-_a-z0-9]+\s*,?)*\s*\)/i';

The word "function" is followed by 1 or more spaces (or tabs). The
function name [-_a-z0-9] can be a combination of alpha-numeric
characters, underscore, and dash. Then, there is optional whitespace
between the name of the function and its parameters. The opening
parenthesis "(" for parameters has been escaped (as has the closing
parenthesis). Then, in a repeatable capture group, the parameters can be
grabbed: Indefinite whitespace, an optional $ (because maybe you're not
using a variable, eh?), one or more alpha-numeric, underscore, or dash
characters, followed by indefinite whitespace and an optional comma (if
there are more arguments). After any number of instances of the capture
group, the regex continues by looking for indefinite whitespace followed
by the closing parenthesis for the function text. The "i" switch at the
end simply means that this regex pattern will be treated as
case-insensitive ('APPLE' == 'apple').

If you're not worried about actually splitting up the function
parameters into capture groups, then you can just use a look-ahead to
ensure that you grab everything up till the LAST parenthesis on the
line.

$regex = '/function\s+[-_a-z0-9]+\s*\(.*?\)(?=.*\)[^)]*)/i';

That one probably needs to be tweaked a bit in order to actually grab
the last parenthesis (instead of just checking for its existence). If
you're willing to trust the text you'll be searching through, you can
probably avoid that "last parenthesis" rule altogether, and make a lazy
regex:

$regex = '/function\s+[-_a-z0-9]+\s*\(.*?/i';

Once you get to the opening parenthesis for the function parameters,
that last regex assumes that the rest of the line will also include that
function declaration, and just grabs everything left. If you are using a
regex setup to where the dot marker can also consume newline or carriage
return characters, just throw a "$" at the end of the regex (before the
flags part "/i") in order to tell it just to grab characters until it
reaches the end of the line:

$regex = '/function\s+[-_a-z0-9]+\s*\(.*?$/i';

These are all untested, but hopefully I've given you a nudge in the
right direction. If you are still getting strange behavior out of your
PCRE engine, then perhaps you have a different version installed than
what I'm used to--all of the above should work (perhaps with some very
minor changes) in PHP.

HTH,


// Todd

GOT IT!!

Thanks. 



--- End Message ---
--- Begin Message ---
Hello,

i use in .htaccess
php_flag log_errors 1
php_value error_log  folder/file

seems to be a new behavior that folder/file must be a absolut value. relativ 
path/file raises an open_basedir error which is set up in httpd.conf
but folder/file is not outside open_basedir and is writeable.

Is this correct?

Thanks,
Andre

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


Al wrote:
If anything can do it, it'll be ImageMagick

Adam Randall wrote:
I'm amazed that this either doesn't exist, or is hard to find. I
basically am looking for a way to read in an image into PHP, or shell
out to something on the Linux side, and determine, and see if it has a
barcode in it or not. If it does, I need to decode the barcode so that
I can identify the page as a separator page or not.

Basically, what I'm doing is reading in a PDF or TIF which will
contain multiple pages (probably a lot of pages) and look for a page
containing a barcode. The barcode will identify the page as a
separator page which will be used to split the multipage document into
smaller single or multipage documents.

Has anyone ever heard of anything that might help me in this process?

Adam.


Google "imagemagick barcode" and you get 140,000+ hits

--- End Message ---
--- Begin Message ---
AIUI:



The barcodes are on faxes and whatnot, with no predictable skew, position, nor 
orientation.



You've tried JOCR/GOCR, and they don't do very well.



Here are your options:

1) Shell out the money for that PaperPort OMNI or whatever it is commercial OCR 
product. It *is* better than JOCR/GOCR, in my experience.

[If you Google for OCR you'll find it, as it's the only/best contender, and 
referenced everywhere.]



2) Roll your own with GD. With sufficient skill and time, you can utilize very 
specific knowledge of your content to do even better than the generalized 
commercial solution. I have done this myself for standardized medical documents 
that were scanned in, getting a percentage point or two better than 1)



No matter what you do, OCR will never ever get you 100%.  You WILL need a human 
oversight process on the results that hand-checks everything, or be prepared to 
accept a (small) failure rate.



Set your [client's] expectations properly, or be doomed to frustration 
[failure].





--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: [email protected] [mailto:[email protected]]
> Sent: Thursday, December 18, 2008 10:06 AM
> To: [email protected]
> Subject: Re: [PHP] Read/decode barcodes from an image
> 
> The barcodes are on faxes and whatnot, with no predictable skew,
> position, nor orientation.
> 
> You've tried JOCR/GOCR, and they don't do very well.
> 
> Here are your options:
> 1) Shell out the money for that PaperPort OMNI or whatever it is
> commercial OCR product. It *is* better than JOCR/GOCR, in my
> experience.
> [If you Google for OCR you'll find it, as it's the only/best
contender,
> and referenced everywhere.]
> 
> 2) Roll your own with GD. With sufficient skill and time, you can
> utilize very specific knowledge of your content to do even better than
> the generalized commercial solution. I have done this myself for
> standardized medical documents that were scanned in, getting a
> percentage point or two better than 1)
> 
> No matter what you do, OCR will never ever get you 100%.  You WILL
need
> a human oversight process on the results that hand-checks everything,
> or be prepared to accept a (small) failure rate.
> 
> Set your [client's] expectations properly, or be doomed to frustration
> [failure].

I had always thought that faxes were a big no-no for character
recognition software? I know that we can't use it for one of our OCR
solutions because it is just too... well, crappy. The image quality is
nowhere near what it should be for a successful OCR pass.

As for client expectations: hell yes--tell them not to use a fax machine
in the digital age. Scan the document and e-mail it or something. Where
I work, we've done away with 90% of any fax machine usage in order to
have documents that can be used by our OCR solution.

My 2c,


// Todd

--- End Message ---
--- Begin Message ---
Certainly if the quality of the input can be improved by using some digital 
transfer that is not a fax, go for it...



I assumed the OP already knew that, but perhaps not.



The fax is going to cost you a LOT of accuracy, probably too much to make OCR 
even viable, really, but it depends on the faxes involved.  If it's always the 
same two fax machines, and they are both set at image quality and have good 
feeders, you *might* get halfway decent quality out of them.



If you're talking random faxes from random people, then forget about OCR. Not 
gonna work.



--- End Message ---
--- Begin Message ---
> Unfortunately, in the inherited DeployTask::execute(), "self::$STEPS"

> does not refer to UpdateTask::$STEPS, it refers to DeployTask::$STEPS



Use parent::$STEPS and call it done?



Yes, I know, if you add another layer of class in between, then it's not 
parent:: anymore, but it seems a bit less convoluted than the reflection 
solution, to this naive user...



--- End Message ---
--- Begin Message ---
Still this won't pass the session to the next page.... is there a way to
pass parameters in the url but mask them? maybe that would be easier, since
I do have code that works passing the adminID on the url ...
can a parameter be hashed after the fact?  I tried echo-ing the fields on
the next page and they are not passing...
my code that still doesn't work:

<?php
// start session
  session_start();
 include("inc/dbconn_open.php") ;
 $errs = error_reporting ('E_ALL');

if (isset($_POST['UserName'])) {$UserName = $_POST['UserName'];} else
{$UserName = '';}
if (isset($_POST['Password'])) {$Password = $_POST['Password'];} else
{$Password = '';}

$msg = '';

if (!empty($UserName)) {

    $sql = "SELECT * FROM  admin WHERE  UserName ='$UserName' and Password
='$Password' "
    or die(mysql_error());
    $result = mysql_query ($sql);
    $row = mysql_fetch_object ($result);
    If (mysql_num_rows($result) > 0) {
        $_SESSION['AdminLogin'] = $row['AdminID'];
        header ("Location: Main.php");
    } else {
        $msg = "Invalid Login";
    }
}

?>

--- End Message ---
--- Begin Message ---
1st. Replace your $sql query with this

$sql = sprintf("SELECT * FROM admin WHERE UserName = '%s' AND Password
= '%s'", mysql_real_escape_string($UserName),
mysql_real_escape_string($Password));
$result = mysql_query($sql) or die(mysql_error());

Ólafur Waage
[email protected]

On Thu, Dec 18, 2008 at 3:56 PM, Terion Miller <[email protected]> wrote:
> Still this won't pass the session to the next page.... is there a way to
> pass parameters in the url but mask them? maybe that would be easier, since
> I do have code that works passing the adminID on the url ...
> can a parameter be hashed after the fact?  I tried echo-ing the fields on
> the next page and they are not passing...
> my code that still doesn't work:
>
> <?php
> // start session
>  session_start();
>  include("inc/dbconn_open.php") ;
>  $errs = error_reporting ('E_ALL');
>
> if (isset($_POST['UserName'])) {$UserName = $_POST['UserName'];} else
> {$UserName = '';}
> if (isset($_POST['Password'])) {$Password = $_POST['Password'];} else
> {$Password = '';}
>
> $msg = '';
>
> if (!empty($UserName)) {
>
>    $sql = "SELECT * FROM  admin WHERE  UserName ='$UserName' and Password
> ='$Password' "
>    or die(mysql_error());
>    $result = mysql_query ($sql);
>    $row = mysql_fetch_object ($result);
>    If (mysql_num_rows($result) > 0) {
>        $_SESSION['AdminLogin'] = $row['AdminID'];
>        header ("Location: Main.php");
>    } else {
>        $msg = "Invalid Login";
>    }
> }
>
> ?>
>

--- End Message ---
--- Begin Message ---
Mike -- I've "bottom posted" my reply, as is the convention for this list (and 
most others). Scroll down.

----

From: Mike Peloso [mailto:[email protected]] 
Sent: Thursday, December 18, 2008 9:56 AM
To: Boyd, Todd M.
Subject: Php question from Newsgroup

Todd,
I have attached a few jpgs to show the problems I am having (With both of my 
recent posts)
Any questions you can call me.
The first one shows the value of the php file I am trying to parse.( I cant set 
any of those directives,) I can't set php.ini per dir
The second shows what your REGEX looks like as its being sent to: 
preg_match_all($regex, $test2, $result, PREG_PATTERN_ORDER);
As you can see there is a whole lot of escaping going on here.
Thanks
Mike 

Heres all the code:
<?php
process_uploaded_file('letter');
function process_uploaded_file($fname) {
    // Assumes set of $_POST variables in the form: name, name_fname, 
name_size, name_type
    $_POST[$fname.'_fname'] = $_FILES[$fname]['name'];
    $_POST[$fname.'_size'] = $_FILES[$fname]['size'];
    $_POST[$fname.'_type'] = $_FILES[$fname]['type'];
    $_POST[$fname.'_fname'] = strtr($_POST[$fname.'_fname'],' 
%&*;:"{}[]|\<>,/()%...@!','________________________'); //fix special chars in 
name
    $_POST[$fname.'_fname'] = strtr($_POST[$fname.'_fname'],"'","_");
    $fileHandle = fopen($_FILES[$fname]['tmp_name'], "r");
    $_POST[$fname] =stripslashes(fread($fileHandle, $_POST[$fname.'_size']));
    $test=$_POST[$fname];
    $test3=stripslashes($test);
    //$regex='/function [a-z]* *([$a-zA-Z]*)/';
    //$regex='/function [a-z]* *(?$[a-z]*)?/';
    $regex = '/function\s+[-_a-z0-9]+\s*\((\s*$\?[-_a-z0-9]+\s*,?)*\s*\)/i';

    $functions=do_reg($regex,$test);
}

  function do_reg($regex,$test)
{   $test2=preg_quote($test);
    preg_match_all($regex, $test2, $result, PREG_PATTERN_ORDER);
    return $result = $result[0];
}
?>

----

Mike,

You are using preg_quote(). This will add slashes to every "special" RegEx 
character in your pattern (i.e., parentheses and dollar signs, etc.). Try 
performing your RegEx search without using preg_quote() and let me know if it 
does any better. Also--try to keep your replies on the PHP List, as the 
information in them can be used by others on their own projects.

// Todd 


--- End Message ---
--- Begin Message ---
""Boyd, Todd M."" <[email protected]> wrote in message 
news:[email protected]...
Mike -- I've "bottom posted" my reply, as is the convention for this list 
(and most others). Scroll down.

----

From: Mike Peloso [mailto:[email protected]]
Sent: Thursday, December 18, 2008 9:56 AM
To: Boyd, Todd M.
Subject: Php question from Newsgroup

Todd,
I have attached a few jpgs to show the problems I am having (With both of my 
recent posts)
Any questions you can call me.
The first one shows the value of the php file I am trying to parse.( I cant 
set any of those directives,) I can't set php.ini per dir
The second shows what your REGEX looks like as its being sent to: 
preg_match_all($regex, $test2, $result, PREG_PATTERN_ORDER);
As you can see there is a whole lot of escaping going on here.
Thanks
Mike

Heres all the code:
<?php
process_uploaded_file('letter');
function process_uploaded_file($fname) {
// Assumes set of $_POST variables in the form: name, name_fname, name_size, 
name_type
$_POST[$fname.'_fname'] = $_FILES[$fname]['name'];
$_POST[$fname.'_size'] = $_FILES[$fname]['size'];
$_POST[$fname.'_type'] = $_FILES[$fname]['type'];
$_POST[$fname.'_fname'] = strtr($_POST[$fname.'_fname'],' 
%&*;:"{}[]|\<>,/()%...@!','________________________'); //fix special chars in 
name
$_POST[$fname.'_fname'] = strtr($_POST[$fname.'_fname'],"'","_");
$fileHandle = fopen($_FILES[$fname]['tmp_name'], "r");
$_POST[$fname] =stripslashes(fread($fileHandle, $_POST[$fname.'_size']));
$test=$_POST[$fname];
$test3=stripslashes($test);
//$regex='/function [a-z]* *([$a-zA-Z]*)/';
//$regex='/function [a-z]* *(?$[a-z]*)?/';
$regex = '/function\s+[-_a-z0-9]+\s*\((\s*$\?[-_a-z0-9]+\s*,?)*\s*\)/i';

$functions=do_reg($regex,$test);
}

function do_reg($regex,$test)
{ $test2=preg_quote($test);
preg_match_all($regex, $test2, $result, PREG_PATTERN_ORDER);
return $result = $result[0];
}
?>

----

Mike,

You are using preg_quote(). This will add slashes to every "special" RegEx 
character in your pattern (i.e., parentheses and dollar signs, etc.). Try 
performing your RegEx search without using preg_quote() and let me know if 
it does any better. Also--try to keep your replies on the PHP List, as the 
information in them can be used by others on their own projects.

// Todd
Were getting there....
The only fuction i get is one without any parameters.
I'll play with it, but if you see an error in your regex let me know.
Thanks
Mike 



--- End Message ---
--- Begin Message ---
Hi,
I am looking for some method, how to run php cli script on background in 
windows. It should be started by windows task manager.

Do you have any idea?
Thans, Fanda 



--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Fanda [mailto:[email protected]]
> Sent: Thursday, December 18, 2008 10:50 AM
> To: [email protected]
> Subject: [PHP] CLI in background on windows
> 
> Hi,
> I am looking for some method, how to run php cli script on background
> in
> windows. It should be started by windows task manager.
> 
> Do you have any idea?

I assume by "task manager" you mean "task scheduler"? The Task Manager
is more of a process listing, like "ps" or "top" in Linux.

In the Windows command-line interface (cmd.exe), type "start /?" to give
you an idea of what your options are. As far as "in the background"
goes, Vista's task scheduler can hide the programs it executes from
being viewed by the user. Pre-vista, I think you can just minimize it
(unless it's run on a different account on the same machine other than
the one logged in)...

start /min /b php myscript.php

The "/b" option MIGHT prevent pre-Vista machines from showing the user
that a task is being executed. If it doesn't, then at least "/min" will
keep the window minimized rather than slapping them in the face with it.

HTH,


// Todd

--- End Message ---
--- Begin Message ---
 Yes, it should be "task scheduler". :-) My Windows is in czech, sorry. I was 
trying commands you suggested before, but black window always blinks on screen.

My soulution is to create new windows user and run my tasks under this user. In 
such case tasks run is not visible...

Thanks for your tips,

Fanda



""Boyd, Todd M."" <[email protected]> píse v diskusním príspevku 
news:[email protected]...

> -----Original Message-----
> From: Fanda [mailto:[email protected]]
> Sent: Thursday, December 18, 2008 10:50 AM
> To: [email protected]
> Subject: [PHP] CLI in background on windows
> 
> Hi,
> I am looking for some method, how to run php cli script on background
> in
> windows. It should be started by windows task manager.
> 
> Do you have any idea?

I assume by "task manager" you mean "task scheduler"? The Task Manager
is more of a process listing, like "ps" or "top" in Linux.

In the Windows command-line interface (cmd.exe), type "start /?" to give
you an idea of what your options are. As far as "in the background"
goes, Vista's task scheduler can hide the programs it executes from
being viewed by the user. Pre-vista, I think you can just minimize it
(unless it's run on a different account on the same machine other than
the one logged in)...

start /min /b php myscript.php

The "/b" option MIGHT prevent pre-Vista machines from showing the user
that a task is being executed. If it doesn't, then at least "/min" will
keep the window minimized rather than slapping them in the face with it.

HTH,


// Todd

--- End Message ---
--- Begin Message ---
Robert Cummings a écrit :
On Wed, 2008-12-17 at 10:47 +0000, Richard Heyes wrote:
Floppies hold 1.4 megs now?  Mine don't and they're even dual-sided. :(
What are "Floppies"? Is it a reference to a particular male problem?

If so, then I want to know what dual sided means?

Cheers,
Rob.
and me High Density !!! :)

Truely,
Zeuf

--- End Message ---
--- Begin Message ---
I'm new to PHP 5 and classes, but I've done a lot of ActionScript.

I'm trying to use PHPMailer inside my own class (a service for AMFPHP). I'm having problems getting the data that'spassed into my class's send() method to the instance of the PHPMailer.

Basically, I have this:

class EmailAMF {
  public function send ($from, $to, $subject, $body) {
    require('class.phpmailer.php');

    $phpMail = new PHPMailer();
    $phpMail->From = $from;
    $phpMail->AddAddress($this->to);
    $phpMail->Subject = $subject;
    $phpMail->Body = $body;
    return $phpMail->Send();

  }
}

As far as I can tell, it sends an essentially blank email to nobody (but returns true.

If I replace any of my function variables with strings, like this:

   $phpMail->AddAddress('[email protected]');

the email actually "gets" that data.

What am I missing?

Thanks,
Jim

--- End Message ---
--- Begin Message ---
Jim McIntyre wrote:
> I'm new to PHP 5 and classes, but I've done a lot of ActionScript.
>
> I'm trying to use PHPMailer inside my own class (a service for
> AMFPHP). I'm having problems getting the data that'spassed into my
> class's send() method to the instance of the PHPMailer.
>
> Basically, I have this:
>
> class EmailAMF {
>   public function send ($from, $to, $subject, $body) {
>     require('class.phpmailer.php');
>
>     $phpMail = new PHPMailer();
>     $phpMail->From = $from;
>     $phpMail->AddAddress($this->to);
>     $phpMail->Subject = $subject;
>     $phpMail->Body = $body;
>     return $phpMail->Send();
>
>   }
> }
>
> As far as I can tell, it sends an essentially blank email to nobody
> (but returns true.
>
> If I replace any of my function variables with strings, like this:
>
>    $phpMail->AddAddress('[email protected]');
>
> the email actually "gets" that data.
>
> What am I missing?
>
> Thanks,
> Jim
>
$this -> to

it has no meaning in the scope of your class.






--- End Message ---
--- Begin Message ---
metastable wrote:
Jim McIntyre wrote:
    $phpMail = new PHPMailer();
    $phpMail->From = $from;
    $phpMail->AddAddress($this->to);
    $phpMail->Subject = $subject;
    $phpMail->Body = $body;
    return $phpMail->Send();

$this -> to

it has no meaning in the scope of your class.

Apparently, neither do the other variable names. If I replace that with a string containing my email address, it sends an email... but everything else in the email is blank - no body, no subject, etc.

How do I reference the arguments passed to the function when setting properties or calling methods of the instance of PHPMailer?
--- End Message ---
--- Begin Message ---


Jim McIntyre wrote:
metastable wrote:
Jim McIntyre wrote:
    $phpMail = new PHPMailer();
    $phpMail->From = $from;
    $phpMail->AddAddress($this->to);
    $phpMail->Subject = $subject;
    $phpMail->Body = $body;
    return $phpMail->Send();

Never mind - I found the problem. It was a lowly typo. Ugh.

-Jim

--- End Message ---
--- Begin Message ---
Hello,

I have a text file encoded in utf-8.
i am using fopen/fgets/echo etc..

how do i display these utf8 characters from the file on the web?

I have tried different combinations of
header("Content-Type: text/html; charset=iso-8859-1");
header("Content-Type: text/html; charset=utf-8")
and
utf8_decode/utf8_encode functions

I can't seem to get the characters from the file to display as non-giberish on the web.

if i set the charset=utf8, and type the unique characters in directly to my document (hard coded) and save the document as utf8, then the characters display properly on the web.

examples:
1) save file as utf-8, web produces correct characters
<?php
header("Content-Type: text/html; charset=utf-8");
?>
<HTML><BODY>
[type special characters here using russian keyboard layout]
</BODY></HTML>

2) save file as ASCI, web produces [giberish]
<?php
header("Content-Type: text/html; charset=iso-8859-1");
?>
<HTML><BODY>
<?php
echo utf8_decode(fgets($handle));
?>
</BODY></HTML>

3) save file as utf-8, web produces [giberish]
<?php
header("Content-Type: text/html; charset=utf-8");
?>
<HTML><BODY>
<?php
echo fgets($handle));
?>
</BODY></HTML>

Thanks for your help,
dK


--- End Message ---

Reply via email to