php-windows Digest 17 Jan 2007 14:31:07 -0000 Issue 3115

Topics (messages 27390 through 27396):

Re: Ereg problems
        27390 by: Niel Archer
        27391 by: Daniel Anderson
        27393 by: Beauford
        27394 by: Daniel Anderson
        27395 by: Niel Archer

Re: COM surgery
        27392 by: tg-php.gryffyndevelopment.com
        27396 by: tg-php.gryffyndevelopment.com

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 ---
Hi

  What you've written doesn't match the description you gave. As a
regular expression "([0-9][A-Z][a-z][-_.'\ ])" means a digit followed by
an uppercase letter followed by a lower case letter followed by (hyphen
or underscore or mid-dot or single quote or space). This is a total of
four characters only.
  Is your string only supposed to be four characters in that format?
  I had assumed from your original post, that you wanted a variable
length string, that could only contain alphanumeric characters plus
hyphen, underscore, and single quote (I missed the space). All of which
in any position.  If this is not the case please describe exactly what
it is you're trying to achieve.



Niel

--- End Message ---
--- Begin Message ---
I think this is your solution:


--------------------------------------------------------------------------------

$string = "~YOUR STRING~"

if (!eregi_replace("[0-9A-Za-z -_']","",$string))
     {
          echo "string allowed";
     }
else {
          echo "string disallowed";
 }

--------------------------------------------------------------------------------


I tested it with the following strings:

$string = "Daniel Anderson"
    Returned "string allowed".

$string = "Daniel Anderson!!"
    Returned "string disallowed".

$string = "Daniel, yo Anderson"
    Returned "string disallowed".

$string = "Daniel_Anderson-Innit"
    Returned "string allowed"

I think that may be your solution :)

Hope it helps! Try to keep all the collections like "a-z" within one set of 
square brackets.

Warmest Regards,
Dan


----- Original Message ----- 
From: "Beauford" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Tuesday, January 16, 2007 4:20 PM
Subject: RE: [PHP-WIN] Ereg problems


> Nope, doesn't work for me. I think what I'm trying to do must not be
> possible. I've been at this for two days now. I changed yours to this - ereg
> ("([0-9][A-Z][a-z][-_.'\ ])"  but it always says that it is invalid. The
> last one after the slash is supposed to be a space - I have to have a space.
> I don't need a length.
> 
>> -----Original Message-----
>> From: bedul [mailto:[EMAIL PROTECTED] 
>> Sent: January 15, 2007 11:48 PM
>> To: Beauford
>> Subject: Re: [PHP-WIN] Ereg problems
>> 
>> <?
>> $nlong=strlen($username);
>> if(ereg ("([0-9][A-Z][a-z][_-]{$nlong})", $username){
>>     echo "allowed";
>> }else{
>>     echo "disallowed";
>> 
>> }
>> 
>> //taken from ereg help
>> /*
>> if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs)) {
>>     echo "$regs[3].$regs[2].$regs[1]";
>> } else {
>>     echo "Invalid date format: $date";
>> }
>> */
>> ?>
>> 
>> ----- Original Message -----
>> From: "Beauford" <[EMAIL PROTECTED]>
>> To: <[email protected]>
>> Sent: Tuesday, January 16, 2007 10:59 AM
>> Subject: [PHP-WIN] Ereg problems
>> 
>> 
>> > Hi,
>> >
>> > Without getting into a long drawn out discussion, can 
>> anyone show me a 
>> > way to validate a string that is input from a form.
>> >
>> > I want to allow the following: a to z, A to Z, 0 to 9, and "_-'" 
>> > (without the double quotes) and spaces. I have now been screwing 
>> > around with this
>> for
>> > over 8 hours. There are other issues as well that has been 
>> compoudning
>> this,
>> > but this would be a great start to solving my issue.
>> >
>> > Thanks
>> >
>> > --
>> > PHP Windows Mailing List (http://www.php.net/) To 
>> unsubscribe, visit: 
>> > http://www.php.net/unsub.php
>> >
>> 
>> 
>> 
> 
> -- 
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
>

--- End Message ---
--- Begin Message ---
No, this is what I said in my original email.

I want to allow the following: a to z, A to Z, 0 to 9, and "_-'" (without
the double quotes) and spaces. 

I don't care about length, I don't care about order. I just want the user to
be able to use these characters. A to z A to Z 0 to 9 and the character _-'
and spaces.

So ABCDE __-' is valid, so is _-aaaBBcD' __

Thanks

> -----Original Message-----
> From: Niel Archer [mailto:Niel Archer] On Behalf Of Niel Archer
> Sent: January 16, 2007 11:46 AM
> To: [email protected]
> Subject: Re: [PHP-WIN] Ereg problems
> 
> Hi
> 
>   What you've written doesn't match the description you gave. 
> As a regular expression "([0-9][A-Z][a-z][-_.'\ ])" means a 
> digit followed by an uppercase letter followed by a lower 
> case letter followed by (hyphen or underscore or mid-dot or 
> single quote or space). This is a total of four characters only.
>   Is your string only supposed to be four characters in that format?
>   I had assumed from your original post, that you wanted a 
> variable length string, that could only contain alphanumeric 
> characters plus hyphen, underscore, and single quote (I 
> missed the space). All of which in any position.  If this is 
> not the case please describe exactly what it is you're trying 
> to achieve.
> 
> 
> 
> Niel
> 
> --
> PHP Windows Mailing List (http://www.php.net/) To 
> unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> 

--- End Message ---
--- Begin Message ---
Then I think this will do the trick for you :)

--------------------------------------------------------------------------------

$string = "~YOUR STRING~"

if (!eregi_replace("[0-9A-Za-z -_']","",$string))
    {
         echo "string allowed";
    }
else {
         echo "string disallowed";
}

--------------------------------------------------------------------------------


Warmest Regards,
Dan

----- Original Message ----- From: "Beauford" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Tuesday, January 16, 2007 5:59 PM
Subject: RE: [PHP-WIN] Ereg problems


No, this is what I said in my original email.

I want to allow the following: a to z, A to Z, 0 to 9, and "_-'" (without
the double quotes) and spaces.

I don't care about length, I don't care about order. I just want the user to be able to use these characters. A to z A to Z 0 to 9 and the character _-'
and spaces.

So ABCDE __-' is valid, so is _-aaaBBcD' __

Thanks

-----Original Message-----
From: Niel Archer [mailto:Niel Archer] On Behalf Of Niel Archer
Sent: January 16, 2007 11:46 AM
To: [email protected]
Subject: Re: [PHP-WIN] Ereg problems

Hi

  What you've written doesn't match the description you gave.
As a regular expression "([0-9][A-Z][a-z][-_.'\ ])" means a
digit followed by an uppercase letter followed by a lower
case letter followed by (hyphen or underscore or mid-dot or
single quote or space). This is a total of four characters only.
  Is your string only supposed to be four characters in that format?
  I had assumed from your original post, that you wanted a
variable length string, that could only contain alphanumeric
characters plus hyphen, underscore, and single quote (I
missed the space). All of which in any position.  If this is
not the case please describe exactly what it is you're trying
to achieve.



Niel

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




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



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

  As I said before I don't use posix regexes (i.e. ereg), as they're not
binary safe and can be much slower than the PCRE versions. the PCRE
equivalent of what you want is:

if (preg_match("/^[-A-Za-z0-9_' ]+$/", $string)}:
  echo "string valid";
else:
  echo "string invalid";
endif;

  The "A-Za-z0-9_" can be simplified to "\w" meaning any 'word'
character.
  The slashes '/' are required as delimeters around a regex with PCRE.
  The '^' and '$' anchor to beginning and end. This makes sure you're
testing the whole string not just a part of it, otherwise it would match
up to the first invalid character but still make a match.

  I use this kind of test frequently myself, so I know it is possible
and fairly simple to do.


Niel

--- End Message ---
--- Begin Message ---
There's thousands of things you can access via COM.  Windows uses it 
extensively.  Every application in Microsoft Office uses COM.  I've used COM 
between Excel and MapPoint to generate maps (and yeah, I created a PHP script 
to access MapPoint directly.. but it was just easier to do it via Excel).

Check out some of the examples in the PHP documentation:

http://www.php.net/manual/en/ref.com.php


Also, if you want to mess around with COM, try loading up MS Word or Excel (I 
like Excel myself since you can use the cells to output your data and keep it 
somewhat straight for debugging and general display).

Also, MS Office apps have a fairly nice debugger that is aware of the COM 
references you've set up so it will autocomplete methods and properties as you 
type (even give you lists).  I found it easier to sketch out what I needed in 
there first, then work on translating it to PHP.

Another tip...  you won't just be dealing with methods (actions, 'verbs') and 
properties (adjectives) but also objects will be returned (of various types) 
and collections (of objects).

Here's an example from mappoint:

# Connect to MapPoint and define some objects
$comobjMapPoint = new COM("mappoint.application") or die("Unable to instantiate 
mappoint");
$comobjMapPoint -> Activate();
$comobjMapPoint -> Visible = FALSE;
$mapobjActiveMap = $comobjMapPoint -> ActiveMap();
$routeobjActiveRoute = $mapobjActiveMap -> ActiveRoute();


Also.. you might find it helpful to search for the application you're trying to 
connect to and the key words "object model", at least in the Microsoft world.  
Despite MS being kinda dumb sometimes, the Excel and MapPoint object models 
online are actually really well documented.

http://msdn2.microsoft.com/en-us/library/wss56bz7(vs.80).aspx

http://msdn2.microsoft.com/en-us/library/aa723478.aspx

Hopefully that'll give you a good headstart.   But if your quest was "what 
applications can I connect to via COM", the answer is going to be too long to 
list.. You should figure out what you WANT to connect to and see if it supports 
COM.  Lots of stuff does.

Good luck!

-TG

= = = Original message = = =

----- Original Message -----
From: "gunawan" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Tuesday, January 16, 2007 11:57 AM
Subject: COM surgery


> i read the com and interested using in my program..
> but the help (php manual chm) don't give what i need
> example :
> $word = new COM("word.application") or die("Unable to instantiate Word");
> echo "Loaded Word, version $word->Version\n";
>
> metods:
> $obj = new COM("Application.ID");
> what i want to build nextt is not a main problem right now, what i want to
> ask was about how many Aplication.id able to receive by this com
> i have only:
> 1. word.application
> 2. ADODB.Connection
> 3. excel.application
> are there any application.id ??
>
>


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

--- End Message ---
--- Begin Message ---
Ok, I see two main questions/problems..

1. An example of COM with Excel

2. How do you use COM with Word to set font size 20 and centered text?


Keep in mind that there may be better ways to solve the problems you have, but 
for the time being we'll use this as an excuse to play with COM.

#1 - There are at least 6 examples of using COM with Excel on php.net, so check 
there first.

Address: http://us2.php.net/manual/en/ref.com.php
Authors:
a dot kulikov at pool4tool dot com 13-Mar-2006 09:36
bruce at yourweb dot com dot au 23-Apr-2005 05:47
Jack dot CHLiang at gmail dot com 10-Apr-2005 10:02
markshane1 at fuse dot net 10-May-2004 04:41
dwt at myrealbox dot com 27-Aug-2002 03:31
madon at cma-it dot com 07-Mar-2002 12:59

#2. Again, check the page above and look for these authors:
pelegk2 at walla DOT co DOT il 13-Feb-2005 08:49
Shawn Coppock 11-Aug-2004 01:15
angelo [at] mandato <dot> com 03-Jun-2004 11:37
#no author name# 03-Oct-2003 12:55
php at dictim dot com 06-Sep-2003 01:17
admin at purplerain dot org 19-Apr-2002 04:34

Since you had a specific question about Word, let's see if we can give a quick 
example.

Starting with Shawn Coppock's example, because he already has the font size 
done, we just need to figure out how to do centering.

The easiest way to do this is to figure out how to do it in Word VBA (Visual 
Basic for Applications) then figure out the equivalent PHP.  The built in VBA 
editor for MS Office apps is actually really good for learning on.  Hit ALT-F11 
to pull up the VBA editor, then right click on the tree on the left and do 
"INSERT MODULE".

Here's what I got in VBA:

Sub main()
  Selection.Font.Size = 20
  Selection.TypeText ("test")
  Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
End Sub

Took a minute to find the proper way to do 'center', but apparently it's a 
paragraph property.

Now using the PHP example...

<?php

define("wdAlignParagraphCenter", 1);

$content = "test";
$word= new COM("word.application") or die("Unable to create Word document");
print "Loaded Word, version {$word->Version}\n";
// TG: Changed this to 1 so you can see what's going on
$word->Visible = 1;
$word->Documents->Add();
$word->Selection->Font->Size = 20;
$word->Selection->TypeText("$content");
$word->Selection->ParagraphFormat->Alignment = wdAlignParagraphCenter;

$word->quit();
echo "done";
?>

Notice that I defined "wdAlignParagraphCenter".  Because in the VBA example, we 
just did "= wdAlignParagraphCenter".  This is a constant pre-defined inside 
Word.  Easiest way to figure out what the actual value is, is to do:

Selection.TypeText (wdAlignParagraphCenter)

This outputs "1".. therefore, defining PHP constant of the same name to be "1".

Sorry, don't have time to test this, but it should be close to correct.

One note about COM stuff in general.  After you run your script a few things, 
check your process list and make sure the application isn't still running in 
the background.  I forget exactly what it was, but if you don't close your COM 
application properly, it'll stay running and take up valuable system memory.

$word->close();  // Only closes the document and not the app?
$word->quit();   // Quits and closes application?

The only other tip I can give you is that in Excel, there are two ways of 
referring to cells.  One like "A1" (column A, row 1) and one is "1,1" (column 
1, row 1).  I never found a way to use "A1" type notation via PHP.  You may be 
able to, but by default you're probably going to have to use "1,1" type 
notation.

This should be more than enough to get you going.  Check out the other 
examples, learn how to write VBA code inside Word and Excel then translate it 
to PHP.  Check out the lists of objects, properties, methods and collections on 
Microsoft.com listed under Word Object Model and Excel Object Model.

It will take a lot of trial and error before you get things right, probably.  
But most of it's not too difficult if you get the basics down.

-TG

= = = Original message = = =

----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Wednesday, January 17, 2007 12:04 AM
Subject: Re: [PHP-WIN] Fw: COM surgery


> There's thousands of things you can access via COM.  Windows uses it
extensively.  Every application in Microsoft Office uses COM.  I've used COM
between Excel and MapPoint to generate maps (and yeah, I created a PHP
script to access MapPoint directly.. but it was just easier to do it via
Excel).
>
> Check out some of the examples in the PHP documentation:
>
> http://www.php.net/manual/en/ref.com.php
>
>
> Also, if you want to mess around with COM, try loading up MS Word or Excel
(I like Excel myself since you can use the cells to output your data and
keep it somewhat straight for debugging and general display).
>
> Also, MS Office apps have a fairly nice debugger that is aware of the COM
references you've set up so it will autocomplete methods and properties as
you type (even give you lists).  I found it easier to sketch out what I
needed in there first, then work on translating it to PHP.
>
> Another tip...  you won't just be dealing with methods (actions, 'verbs')
and properties (adjectives) but also objects will be returned (of various
types) and collections (of objects).
>
> Here's an example from mappoint:
>
> # Connect to MapPoint and define some objects
> $comobjMapPoint = new COM("mappoint.application") or die("Unable to
instantiate mappoint");
> $comobjMapPoint -> Activate();
> $comobjMapPoint -> Visible = FALSE;
> $mapobjActiveMap = $comobjMapPoint -> ActiveMap();
> $routeobjActiveRoute = $mapobjActiveMap -> ActiveRoute();
>
>
> Also.. you might find it helpful to search for the application you're
trying to connect to and the key words "object model", at least in the
Microsoft world.  Despite MS being kinda dumb sometimes, the Excel and
MapPoint object models online are actually really well documented.
>
thx for reply

i was gonna use com for word and excel
for excel.. i'm not using com(excel) since i don't have example related to
excel.. and then i created csv for read by ms Excel.. it kinda work for
now.. but the problem in csv is about the comma ","  or semi-column ";"
my country using ";" for seperated data
but in general using ","
if you have an example related to com(excel).. can u post in here

WORD...problem
sry if would be better if i put in new email..
i created a med-app using php.. Medical Check-Up document. the problem about
MCU is the clerk or the person who input data always lost the data and mess
up with everything.
in the past, they using word to type all kind patient data.

they use some kind templates where they always open then saveas new name and
then edit. if type for 5 person a day.. is no problem.. but 10-30
patient!?!??
they using name as file name like Joko bodo. but the person who named as
joko are not one (like mark in america).
i came up idea to build a form in php for their type.. leave the prog and
howto build form to me.. let's jump to the main problem.

the report must be print and doctor sometimes want to bring home the work
home. Then i have conclusion to create all data to a word..

the problem i have is.. format on the word.. some have big.. in center have
tab and soon
i need all example related to word.. like make the font are big (size 20)
and center like in htm

sry about my languages


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

--- End Message ---

Reply via email to