php-general Digest 10 Apr 2006 16:25:19 -0000 Issue 4064

Topics (messages 233649 through 233673):

Re: How to use check box in CakePHP?
        233649 by: Chris
        233650 by: Pham Huu Le Quoc Phuc
        233651 by: Chris
        233652 by: Chris

PHP + DDE live feed
        233653 by: C.F. Scheidecker Antunes
        233654 by: Chris

mod_rewrite q's: syntax?
        233655 by: Micky Hulse
        233656 by: Chris
        233657 by: Micky Hulse
        233659 by: Micky Hulse

Re: stripping enclosed text from PHP code
        233658 by: Rafael
        233661 by: Robin Vickery

imap_search and multiple criteria
        233660 by: James Nunnerley

String /pattern formatting extraction question
        233662 by: Andy
        233665 by: Barry
        233669 by: Andy
        233670 by: Robin Vickery

Re: IP Address Filtering - Problem Continues
        233663 by: Rahul S. Johari
        233664 by: Rahul S. Johari

RSS Generation
        233666 by: Robbert van Andel
        233667 by: Michael Crute
        233671 by: Greg Schnippel

Re: function by reference
        233668 by: tedd
        233673 by: Robert Cummings

Re: Argument passed by reference?
        233672 by: Joe Henry

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        php-general@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
Pham Huu Le Quoc Phuc wrote:
Hi everybody!
I want to use a checkbox in Add, Edit form with CakePHP.
How to do? Please help me!

You know cake has documentation right?

http://manual.cakephp.org/


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

--- End Message ---
--- Begin Message ---
Could you give me a example?

----- Original Message ----- 
From: "Chris" <[EMAIL PROTECTED]>
To: "Pham Huu Le Quoc Phuc" <[EMAIL PROTECTED]>
Cc: <php-general@lists.php.net>
Sent: Monday, April 10, 2006 10:39 AM
Subject: Re: [PHP] How to use check box in CakePHP?


> Pham Huu Le Quoc Phuc wrote:
> > Hi everybody!
> > I want to use a checkbox in Add, Edit form with CakePHP.
> > How to do? Please help me!
> 
> You know cake has documentation right?
> 
> http://manual.cakephp.org/
> 
> 
> -- 
> Postgresql & php tutorials
> http://www.designmagick.com/
> 

--- End Message ---
--- Begin Message ---
Pham Huu Le Quoc Phuc wrote:
Could you give me a example?

Read the documentation or ask on their mailing list / forum.


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

--- End Message ---
--- Begin Message ---
Pham Huu Le Quoc Phuc wrote:
Could you give me a example?

I found your question quite easily in the manual:

http://manual.cakephp.org/pages/ch09s01#d0e1498

checkbox ($fieldName, $title=null, $htmlAttributes=null, $return=false)

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

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

I have an Excel spreadsheet that is automatically updated with quotes. I am doing a project for my BS and I need to grab the information from this spreadsheet and populate a MySQL database. Any ideas on how to accomplish that with PHP? The spreadsheet uses a live DDE feed to fetch information from a third party service and needs to be opened.

This is not a matter of reading a static XLS spreadsheet but what I need is a DDE way to talk to the open spreadsheet and update the database when the cells are changed or have a 1 minute loop to go over the cells.

I understand that I can do that with Java with a commercial package called Java DDE as well but if there is a way with PHP I prefer.

Thanks,

C.F.

--- End Message ---
--- Begin Message ---
C.F. Scheidecker Antunes wrote:
Hello,

I have an Excel spreadsheet that is automatically updated with quotes. I am doing a project for my BS and I need to grab the information from this spreadsheet and populate a MySQL database. Any ideas on how to accomplish that with PHP? The spreadsheet uses a live DDE feed to fetch information from a third party service and needs to be opened.

This is not a matter of reading a static XLS spreadsheet but what I need is a DDE way to talk to the open spreadsheet and update the database when the cells are changed or have a 1 minute loop to go over the cells.

There are a few packages on phpclasses.org which may do what you want: http://www.phpclasses.org

They all seem to use the COM object (http://www.php.net/com) which only works on windows.

This package might help also:
http://sourceforge.net/projects/phpexcelreader/

and should work anywhere.

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

--- End Message ---
--- Begin Message ---
Hi all... sorry if this is OT for PHP list... Maybe a reply off-list?

I just wanted to share my .htaccess file in the hopes that I can
hone/fool-proof-a-tize it as much as possible via your feedback and
suggestions.

Here is what I got so far...

I start by turning-on error reporting, then I am converting all non www
traffic to www traffic, and I finish things up by removing "index.php" from
the site url...

[code] -->

# Turn-on PHP error messaging:
php_value display_errors 1
php_value error_reporting 2047

# Power-up the rewrite engine:
RewriteEngine on

# Redirect all non-www traffic:
RewriteCond %{HTTP_HOST} ^mydomain\.com$
RewriteRule ^.*$ http://www.mydomain.com%{REQUEST_URI} [R=permanent,L]

# Remove index.php from url:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+) index.php/$1 [L]


<-- [/code]

What I want to do:

I would like to use mod_rewrite to forward all requests for
http://www.mydomain.com (or http://mydomain.com) to
www.mydomain.com/folder/file.php

Questions:

1. How is my code looking so far? Any potential pitfalls that you can see?
2. Can I combine the conditions and rules into one, more compact, script?
3. Any suggestions on how I would go about adding-in a rule/condition to
redirect users to "....com/folder/file.php" as stated above?

Many TIA,
Sorry if OT.
Cheers,
Micky

--- End Message ---
--- Begin Message ---
Micky Hulse wrote:
Hi all... sorry if this is OT for PHP list... Maybe a reply off-list?

I just wanted to share my .htaccess file in the hopes that I can
hone/fool-proof-a-tize it as much as possible via your feedback and
suggestions.

Here is what I got so far...

I start by turning-on error reporting, then I am converting all non www
traffic to www traffic, and I finish things up by removing "index.php" from
the site url...

[code] -->

# Turn-on PHP error messaging:
php_value display_errors 1
php_value error_reporting 2047

# Power-up the rewrite engine:
RewriteEngine on

# Redirect all non-www traffic:
RewriteCond %{HTTP_HOST} ^mydomain\.com$
RewriteRule ^.*$ http://www.mydomain.com%{REQUEST_URI} [R=permanent,L]

# Remove index.php from url:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+) index.php/$1 [L]


<-- [/code]

What I want to do:

I would like to use mod_rewrite to forward all requests for
http://www.mydomain.com (or http://mydomain.com) to
www.mydomain.com/folder/file.php

Questions:

1. How is my code looking so far? Any potential pitfalls that you can see?
2. Can I combine the conditions and rules into one, more compact, script?
3. Any suggestions on how I would go about adding-in a rule/condition to
redirect users to "....com/folder/file.php" as stated above?

Do you need to do it with a mod_rewrite?

if not, you can do it easily in php:

header('location: folder/file.php');
exit();

in index.php.

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

--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Chris [mailto:[EMAIL PROTECTED] 
> Do you need to do it with a mod_rewrite?
> 
> if not, you can do it easily in php:
> 
> header('location: folder/file.php');
> exit();
> 
> in index.php. 


Unfortunately, yes... I am using a CMS, and my current setup is forcing me
into using the more complicated mod_rewrite.

Well, not that it is a bad thing... seems like mod_rewrite is more
search-engine/bot friendly.

Thanks for the tip though, I really appreciate your time.

Cheers,
Micky

--- End Message ---
--- Begin Message ---
Well, I added this to the end of my .htaccess:

# Set the index page:
RedirectMatch ^/$ http://mydomain.com/folder/folder/index.php

Seems to work well, but I am still concerned about
pitfalls/optimization/consolidation... er, perfection? ;)

TIA, Cheers,
Micky

--- End Message ---
--- Begin Message ---
Winfried Meining wrote:
I am writing on a script that parses a PHP script and finds all function calls to check, if these functions exist. To do this, I needed a function that would strip out all text, which is enclosed in apostrophes or quotation marks. This is somewhat tricky, as the script needs to be aware of what really is an enclosed text and what is PHP code. Apostrophes in quotation mark enclosed text should be ignored and quotation marks in apostrophe enclosed text should be ignored, as well. Similarly, escaped apostrophes in apostrophe enclosed text and escaped quotation marks in quotation mark enclosed text should be ignored. The following function uses preg_match to do this job.
[···]
I noticed that this function is very slow, in particular because
preg_match("/^(.*)some_string(.*)$/", $text, $matches);

always seems to find the *last* occurrence of some_string and not the *first* (I would need the first). There is certainly a way to write another version where one looks at every single character when going through $text, but this would make the code much more complex.

IIRC regexp search from left to right but match from right to left, hence going trough the string while the first part matches and going backwards every time the next part fails to match, and so on for the whole expression, that's why "(?>...)", "once-only subpatterns", exists for.

Now, you're telling (from left to right) to look for "any sequence of any characters followed by 'some_string' and, once again, followed by any sequence of any characters". As long as "(.*)" matches it will loop the whole string till it fails, once it does it will try to match "some_text", if it doesn't it will try to match "some_string" once again from the current position minus one and so on, until it matches (or "(.*)" fails --at the beginning of the string), after "some_string" matches it will repeat the first step for the second "(.*)" on the pattern, so the process will be quite slow.
--I hope this has had some sense for you (somehow it lost it for me)

Also, by default regexp are "greedy", which means "+" and "*" meta-characters will go on and on. In your case, you most likely will need to "limit" this behaviour by specifying them as "ungreedy" (that is, it will try to match the next part after each "+"/"*" matches), you can do this adding a "?" after these meta-characters (e.g. ".+?-")

I wonder, if there is a faster *and* simple way to do the same thing.

        Mhh...  what about something like
  preg_replace('/(["\']).*?(?<!\\\)\\1/X', '', $code)
? it's not 100% accurate, though, if you find something like '\\' it will fail --I guess you should replace these before running the regexp

After trying a little, I found that this code below seems to be quite acceptable, you may want to try it:
  /**
   * Returns an array with the identified function-calls found
   * (including "function declarations", e.g. "function my_func")
   *
   * @param     string  $code
   * @return    string
   * @since     Mon Apr 10 01:13:28 CDT 2006
   * @author    rsalazar
   */
  function getFunctionCalls( $code ) {
      $result = FALSE;
      // try to strip away literal strings
      $code   = preg_replace('/(["\']).*?(?<!\\\)\\1/X', '', $code);
      // look for "function calls"
      if ( preg_match_all('/(?>((?:(?<=\b)function\s+)?\w+)\s*)\(/Xi',
                          $code, $arr_matches) ) {
          $result = $arr_matches[1];
      }
      return  $result;
  } // getFunctionCalls()

I recommend you:
-> http://php.net/pcre
 > http://php.net/manual/en/reference.pcre.pattern.syntax.php
 > http://php.net/manual/en/reference.pcre.pattern.modifiers.php
--
Atentamente,
J. Rafael Salazar Magaña
Innox - Innovación Inteligente
Tel: +52 (33) 3615 5348 ext. 205 / 01 800 2-SOFTWARE
http://www.innox.com.mx

--- End Message ---
--- Begin Message ---
On 09/04/06, Winfried Meining <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I am writing on a script that parses a PHP script and finds all function calls
> to check, if these functions exist. To do this, I needed a function that would
> strip out all text, which is enclosed in apostrophes or quotation marks. This
> is somewhat tricky, as the script needs to be aware of what really is an
> enclosed text and what is PHP code.

So use the built in tokenizer functions which know exactly what's
enclosed text and what is php code. Much quicker and more reliable
than trying to do the same job with regular expressions.

http://se.php.net/tokenizer

  -robin

--- End Message ---
--- Begin Message ---
Does the imap_search support multiple criteria?

 

I've got the following successfully returning the correct results:

 

<?php

$search[0] = "BODY \"test\"";

$search[1] = "SUBJECT \"test\"";

 

foreach ($search as $criteria) {

            $search_result[]=$imap_search($mailbox,$criteria,$SE_UID);

}

?>

 

However, when you try and put them in the same search 

e.g. $search = "BODY \"test\" OR SUBJECT \"test\""

 

It fails...

 

The only way in which I can see this can be done is by joining the various
arrays that are returned.  Is this best?

 

Thanks

Nunners


--- End Message ---
--- Begin Message ---
Hi to all, 

I have the following pattern for a string:

text1 /ptext2 /otext3

Now, I want to extract the text by "patterns" from this string by the following 
rule:

no pattern -> text1 (what is before /o or /p)
/p -> text2 (what is after /p)
/o -> text3 (what is after /o)

The order betweeen /o and /p can be switched, so there is no rule that /p is 
before /o.

How can I do this? I tried ereg but no success.

Andy.

--- End Message ---
--- Begin Message ---
Andy wrote:
Hi to all,
I have the following pattern for a string:

text1 /ptext2 /otext3
Does it always look like that?
text1(whitespace)/ptext2(whitespace)/otext3

Then use explode to create an array from it
explode (" ",$stringpattern);

Now, I want to extract the text by "patterns" from this string by the following 
rule:

no pattern -> text1 (what is before /o or /p)
/p -> text2 (what is after /p)
/o -> text3 (what is after /o)
Here you can use ereg and foreach
foreach ($stringpattern as $key => $value)
  {
    $variable = substr_count("/",$value);
    if ($variable > 0) / has been found now extract the first two chars
  }

Or something like that ~


--
Smileys rule (cX.x)C --o(^_^o)
Dance for me! ^(^_^)o (o^_^)o o(^_^)^ o(^_^o)

--- End Message ---
--- Begin Message ---
text1 /ptext2 /otext3
Does it always look like that?
text1(whitespace)/ptext2(whitespace)/otext3

The ideea is to extract the texts before and between /o and /p.
$html = "asdäüü ö ö vf /pxtestxx/ostestss";
eregi("^([^/.*]*)", $html, $reg); print_r($reg); //text is in reg[1]
eregi("^(.*)/p([^/.*]*)", $html, $reg); print_r($reg); //text is in reg[2]
eregi("^(.*)/o([^/.*]*)", $html, $reg); print_r($reg); //text is in reg[2]


This example works, but I thought there might be a better way to extract the
texts, with a single ereg or preg_match.

Regards,
Andy.

----- Original Message ----- From: "Barry" <[EMAIL PROTECTED]>
To: <php-general@lists.php.net>
Sent: Monday, April 10, 2006 4:22 PM
Subject: [PHP] Re: String /pattern formatting extraction question


Andy wrote:
Hi to all, I have the following pattern for a string:

text1 /ptext2 /otext3
Does it always look like that?
text1(whitespace)/ptext2(whitespace)/otext3

Then use explode to create an array from it
explode (" ",$stringpattern);

Now, I want to extract the text by "patterns" from this string by the following rule:

no pattern -> text1 (what is before /o or /p)
/p -> text2 (what is after /p)
/o -> text3 (what is after /o)
Here you can use ereg and foreach
foreach ($stringpattern as $key => $value)
  {
    $variable = substr_count("/",$value);
    if ($variable > 0) / has been found now extract the first two chars
  }

Or something like that ~


--
Smileys rule (cX.x)C --o(^_^o)
Dance for me! ^(^_^)o (o^_^)o o(^_^)^ o(^_^o)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--- End Message ---
--- Begin Message ---
On 10/04/06, Andy <[EMAIL PROTECTED]> wrote:
> >> text1 /ptext2 /otext3
> > Does it always look like that?
> > text1(whitespace)/ptext2(whitespace)/otext3
>
> The ideea is to extract the texts before and between /o and /p.
> $html = "asdäüü ö ö vf /pxtestxx/ostestss";
> eregi("^([^/.*]*)", $html, $reg); print_r($reg); //text is in reg[1]
> eregi("^(.*)/p([^/.*]*)", $html, $reg); print_r($reg); //text is in reg[2]
> eregi("^(.*)/o([^/.*]*)", $html, $reg); print_r($reg); //text is in reg[2]
>
> This example works, but I thought there might be a better way to extract the
> texts, with a single ereg or preg_match.

Well... slightly.

preg_match( '#^(+)/p(.+)/o(.+)$#',
preg_replace('#^(.+)(/o.+)(/p.+)$#', '$1$3$2', $html), $reg);

  -robin

--- End Message ---
--- Begin Message ---
Ave,

I had to eliminate that option because his IP is varying drastically. There
is no range, it's just drastically varying. I wouldn't be surprised if he's
using an IP Spoofing script/program etcetera.


On 4/5/06 11:16 AM, "Jay Blanchard" <[EMAIL PROTECTED]> wrote:

> You could always block a range of IP addresses, but you may cut out a
> legitimate user.
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

Rahul S. Johari
Coordinator, Internet & Administration
Informed Marketing Services Inc.
500 Federal Street, Suite 201
Troy NY 12180

Tel: (518) 687-6700 x154
Fax: (518) 687-6799
Email: [EMAIL PROTECTED]
http://www.informed-sources.com

--- End Message ---
--- Begin Message ---
Ave,

I'm being left with lesser and lesser choices then to try CAPCHTA. I'm gonna
look into it now and see if I need to implement this now.

Thanks.


On 4/5/06 3:52 PM, "tedd" <[EMAIL PROTECTED]> wrote:

> <disclaimer>
> Not that I promote CAPCHTA, but there are simple solutions that will
> slow down some spam while allowing some with vision problems to pass,
> such as --
> 
> http://www.xn--ovg.com/captcha
> 
> -- namely, the graphic selection demo.
> 
> Granted it's not the best, it doesn't solve everything, and I never
> said it did (at least no one can prove it) -- so don't whack me for
> it -- it's just a suggestion.
> </disclaimer>
> 
> tedd

Rahul S. Johari
Coordinator, Internet & Administration
Informed Marketing Services Inc.
500 Federal Street, Suite 201
Troy NY 12180

Tel: (518) 687-6700 x154
Fax: (518) 687-6799
Email: [EMAIL PROTECTED]
http://www.informed-sources.com

--- End Message ---
--- Begin Message ---
I am working on creating some RSS feeds on my website using PHP.  I'm still
learning RSS but it seems easy enough. I managed to create the RSS giving
the file a PHP extension.  When I tried saving it with an xml extension and
adding a .htaccess file to the directory in which the file was saved, I get
prompted to save the file instead of being able to view the file in a
browser.  The only line in the .htaccess file is AddType
application/x-httpd-php xml.  

 

First off, and I'm sorry that this isn't a PHP specific question, but does
RSS require an XML extension?  And if it does, how do I get the server to
serve the PHP file correctly if I rename it with the xml extension?

 

Thanks,

Robbert van Andel

 


--- End Message ---
--- Begin Message ---
On 4/10/06, Robbert van Andel <[EMAIL PROTECTED]> wrote:
> First off, and I'm sorry that this isn't a PHP specific question, but does
> RSS require an XML extension?  And if it does, how do I get the server to
> serve the PHP file correctly if I rename it with the xml extension?

No, you can use any extension you like for the RSS document, including
.php its the contents that matters.

-Mike


--
________________________________
Michael E. Crute
http://mike.crute.org

It is a mistake to think you can solve any major problems just with potatoes.
--Douglas Adams

--- End Message ---
--- Begin Message ---
> ... When I tried saving it with an xml extension and
> adding a .htaccess file to the directory in which the file was saved, I get
> prompted to save the file instead of being able to view the file in a
> browser.  The only line in the .htaccess file is AddType
> application/x-httpd-php xml.

I had similar problems when trying to roll-my-own RSS feed with php.
Michael is right that it doesn't matter what your file extension is
(you probably don't even need that htaccess directive) as long as the
file is served as XML. Try adding a header at the top of the file:

header("Content-type: text/xml; charset=utf-8");

<rss version="2.0">
<channel>

...

I also use the Firefox browser which has a built-in XML browser that
allows me to do a quick validation of the XML. You can also use
www.feedvalidator.org to troubleshoot your feed once its online.

- Greg

--- End Message ---
--- Begin Message ---
It's the same thing for the most part...

<?php

$a = 'f_a';
call_user_func( $a, $p1, $p2, $p3 )

?>

Cheers,
Rob.

Rob:

No way dude -- that was too easy!

Boy, am I in love with this language -- it gives you plenty of shovels to dig yourself in as deep as you want.

Thanks Rob.

tedd
--
--------------------------------------------------------------------------------
http://sperling.com

--- End Message ---
--- Begin Message ---
On Mon, 2006-04-10 at 09:42, tedd wrote:
> >It's the same thing for the most part...
> >
> ><?php
> >
> >$a = 'f_a';
> >call_user_func( $a, $p1, $p2, $p3 )
> >
> >?>
> >
> >Cheers,
> >Rob.
> 
> Rob:
> 
> No way dude -- that was too easy!
> 
> Boy, am I in love with this language -- it gives you plenty of 
> shovels to dig yourself in as deep as you want.

*lol*. personally I prefer the other format which was what I tried to
illustrate with my original example:

<?php

$a = 'f_a';
$a( $p1, $p2, $p3 );

?>

All it means, is that once you have the name of a function in a variable
you can invoke the variable as a function and it will invoke the
function matching the variable's value. Some of this stuff can be really
useful for doing backwards compatibility with older versions of PHP:

<?php

function my_slowass_ctype_alpha( $chars )
{
    return eregi( '^[[:alpha:]]+$, $chars );
}

if( function_exists( 'ctype_alpha' ) )
{
    $ctype_alpha = 'ctype_alpha';
}
else
{
    $ctype_alpha = 'my_slowass_ctype_alpha';
}

if( $ctype_alpha( 'weeeeee' ) )
{
    echo 'Alpha chars only!';
}
else
{
    echo 'Not alpha chars only!';
}

?>

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

--- End Message ---
--- Begin Message ---
On Friday 07 April 2006 5:06 pm, tedd wrote:
> At 1:52 PM -0500 4/6/06, Chris Boget wrote:
> >>The way I understand it, pass by reference in php is determined in
> >>the function definition and not the function call. Something like:
> >
> >You used to be able to pass by reference at run time.  But I see that is
> >no longer allowed... :|  So I guess that makes my question moot.
> >
> >Thanks for your help.
> >
> >thnx,
> >Chris
>
> Chris:
>
> Please forgive my ignorance, but when did that happen?
>
> tedd
> --
> ---------------------------------------------------------------------------
>----- http://sperling.com

I'm not sure when this happened. I'm fairly new to php, myself. Maybe someone 
else could answer that?
-- 
Joe Henry
www.celebrityaccess.com
[EMAIL PROTECTED]

--- End Message ---

Reply via email to