Re: [PHP] Reg Exp help needed

2003-06-24 Thread Don Read

On 24-Jun-2003 Sparky Kopetzky wrote:
 I'm translating (hacking) code from Perl to PHP and have two reg exp
 expressions I can't figure out what they do.
 
 1st: $goodbadnum =~ tr/0-9//cd; I think this one removes any chars that
 are not numbers.
 

Nope. That removes digits '0-9'
$goodbadnum= preg_replace('!\d+!', '', $goodbadnum);

 2nd: $goodbadnum =~ tr/0-9/x/; I think this one replaces and numbers with
 an 'x'.
 

Yep. that replaces every digit with an 'x'.
$goodbadnum= preg_replace('!\d!', 'x', $goodbadnum);

Regards,
-- 
Don Read [EMAIL PROTECTED]
-- It's always darkest before the dawn. So if you are going to 
   steal the neighbor's newspaper, that's the time to do it.

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



RE: [PHP] Reg Exp Help

2002-01-25 Thread Zach Curtis

The password and int_id begin and end in fixed positions.

password begins in position 13 and can occupy up to 8 characters
int_id begins in position 21 and can occupy up to 4 characters

Sometimes a password (or int_id) may occupy all of those fixed position or
only some of the fixed positions, it's variable.


Zach

-Original Message-
From: Edward van Bilderbeek - Bean IT [mailto:[EMAIL PROTECTED]]
Sent: Friday, January 25, 2002 9:58 AM
To: Zach Curtis
Subject: Re: [PHP] Reg Exp Help


how can I see that it isn't a 6 char $password with a 3 char $int_id ??

 This one has a 8 character $password, followed by zero white spaces,
 followed by a single character $int_id
 7d2ad345b

Edward


- Original Message -
From: Zach Curtis [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, January 25, 2002 5:51 PM
Subject: [PHP] Reg Exp Help


 I am trying to code a regular expression that will match at the beginning
of
 the string the contents of $password, followed by 0 or more occurrences of
 white space, followed by the contents of $int_id. The match should be case
 insensitive.

 Here are some examples of the strings:

 This one has a 6 character $password, followed by two white spaces,
followed
 by a single character $int_id
 9a9b9c  z

 This one has a 8 character $password, followed by zero white spaces,
 followed by a single character $int_id
 7d2ad345b

 This one has a 5 character $password, followed by three white spaces,
 followed by a four character $int_id
 d22ad   bbaw


 Here is the regular expression I am trying to use that does not find the
 match and produces Warning: REG_BADRPT.

 (eregi(^\$password+[[:space:]]*+\$int_id, $file_array[$i]))

 Any corrections? Thanks in advance.


 Zach Curtis
 POPULUS


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Reg Exp Help

2002-01-25 Thread Zach Curtis

Hmmm.

I am searching thru a flat file that has been loaded into an array
($file_array[$i]). As each iteration of the array is loaded (each row of the
flat file) , I was trying to search for this unique combination.

The $password is not unique. And $int_id is not unique enough (e.g., a,
b, c, etc.) to be searched for on its own. However, $password and
$int_id joined together is unique.  Also, the $password and $int_id are in a
fixed position in each header row, however, not every row in the flat file
is a header row (no...I didn't create a flat file in this way!).

I am confident the correct regular expression would resolve this. I will
keep thinking about substr() and trim(), but I don't see how to use those to
resolve this issue.


Zach


-Original Message-
From: Edward van Bilderbeek - Bean IT [mailto:[EMAIL PROTECTED]]
Sent: Friday, January 25, 2002 10:29 AM
To: Zach Curtis
Subject: Re: [PHP] Reg Exp Help


but if the positions as fixed, why don't you use the substr, and then trim
th result?

Edward

- Original Message -
From: Zach Curtis [EMAIL PROTECTED]
To: Edward van Bilderbeek - Bean IT [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Friday, January 25, 2002 6:12 PM
Subject: RE: [PHP] Reg Exp Help


 The password and int_id begin and end in fixed positions.

 password begins in position 13 and can occupy up to 8 characters
 int_id begins in position 21 and can occupy up to 4 characters

 Sometimes a password (or int_id) may occupy all of those fixed position or
 only some of the fixed positions, it's variable.


 Zach

 -Original Message-
 From: Edward van Bilderbeek - Bean IT [mailto:[EMAIL PROTECTED]]
 Sent: Friday, January 25, 2002 9:58 AM
 To: Zach Curtis
 Subject: Re: [PHP] Reg Exp Help


 how can I see that it isn't a 6 char $password with a 3 char $int_id ??

  This one has a 8 character $password, followed by zero white spaces,
  followed by a single character $int_id
  7d2ad345b

 Edward


 - Original Message -
 From: Zach Curtis [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Friday, January 25, 2002 5:51 PM
 Subject: [PHP] Reg Exp Help


  I am trying to code a regular expression that will match at the
beginning
 of
  the string the contents of $password, followed by 0 or more occurrences
of
  white space, followed by the contents of $int_id. The match should be
case
  insensitive.
 
  Here are some examples of the strings:
 
  This one has a 6 character $password, followed by two white spaces,
 followed
  by a single character $int_id
  9a9b9c  z
 
  This one has a 8 character $password, followed by zero white spaces,
  followed by a single character $int_id
  7d2ad345b
 
  This one has a 5 character $password, followed by three white spaces,
  followed by a four character $int_id
  d22ad   bbaw
 
 
  Here is the regular expression I am trying to use that does not find the
  match and produces Warning: REG_BADRPT.
 
  (eregi(^\$password+[[:space:]]*+\$int_id, $file_array[$i]))
 
  Any corrections? Thanks in advance.
 
 
  Zach Curtis
  POPULUS
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  To contact the list administrators, e-mail: [EMAIL PROTECTED]
 




 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Reg Exp Help

2002-01-25 Thread Zach Curtis

Here is part of my actual code, if that makes any difference.

$password // this var was retrieved from db
$int_id // this var was retrieved from db

$file_array = file($DOCUMENT_ROOT/dir/file.dat);
$count = count($file_array);
if ($count == 0)
echo pNo records found in .dat file./p;

for ($i = 0; $i  $count; $i++)
{
if (eregi(^\$password+[[:space:]]*+\$int_id, $file_array[$i]))
{
// do stuff
}
}


Zach

-Original Message-
From: Edward van Bilderbeek - Bean IT [mailto:[EMAIL PROTECTED]]
Sent: Friday, January 25, 2002 10:29 AM
To: Zach Curtis
Subject: Re: [PHP] Reg Exp Help


but if the positions as fixed, why don't you use the substr, and then trim
th result?

Edward

- Original Message -
From: Zach Curtis [EMAIL PROTECTED]
To: Edward van Bilderbeek - Bean IT [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Friday, January 25, 2002 6:12 PM
Subject: RE: [PHP] Reg Exp Help


 The password and int_id begin and end in fixed positions.

 password begins in position 13 and can occupy up to 8 characters
 int_id begins in position 21 and can occupy up to 4 characters

 Sometimes a password (or int_id) may occupy all of those fixed position or
 only some of the fixed positions, it's variable.


 Zach

 -Original Message-
 From: Edward van Bilderbeek - Bean IT [mailto:[EMAIL PROTECTED]]
 Sent: Friday, January 25, 2002 9:58 AM
 To: Zach Curtis
 Subject: Re: [PHP] Reg Exp Help


 how can I see that it isn't a 6 char $password with a 3 char $int_id ??

  This one has a 8 character $password, followed by zero white spaces,
  followed by a single character $int_id
  7d2ad345b

 Edward


 - Original Message -
 From: Zach Curtis [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Friday, January 25, 2002 5:51 PM
 Subject: [PHP] Reg Exp Help


  I am trying to code a regular expression that will match at the
beginning
 of
  the string the contents of $password, followed by 0 or more occurrences
of
  white space, followed by the contents of $int_id. The match should be
case
  insensitive.
 
  Here are some examples of the strings:
 
  This one has a 6 character $password, followed by two white spaces,
 followed
  by a single character $int_id
  9a9b9c  z
 
  This one has a 8 character $password, followed by zero white spaces,
  followed by a single character $int_id
  7d2ad345b
 
  This one has a 5 character $password, followed by three white spaces,
  followed by a four character $int_id
  d22ad   bbaw
 
 
  Here is the regular expression I am trying to use that does not find the
  match and produces Warning: REG_BADRPT.
 
  (eregi(^\$password+[[:space:]]*+\$int_id, $file_array[$i]))
 
  Any corrections? Thanks in advance.
 
 
  Zach Curtis
  POPULUS
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  To contact the list administrators, e-mail: [EMAIL PROTECTED]
 




 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Reg Exp Help

2002-01-25 Thread Zach Curtis

YES! I was working that out as well.

One correction though, this line should read:
$temp_int_id = trim(substr($file_array[$i], 21, 4));

I guess the lesson learned is to use substr() when the length of the $string
is fixed. Since I have to use substr() and trim() twice, I wonder if this
has more or less overhead than a single regular expression?

Thank you.


Zach

-Original Message-
From: Edward van Bilderbeek - Bean IT [mailto:[EMAIL PROTECTED]]
Sent: Friday, January 25, 2002 11:36 AM
To: Zach Curtis
Subject: Re: [PHP] Reg Exp Help


You said:
 The password and int_id begin and end in fixed positions.

 password begins in position 13 and can occupy up to 8 characters
 int_id begins in position 21 and can occupy up to 4 characters

 Sometimes a password (or int_id) may occupy all of those fixed position or
 only some of the fixed positions, it's variable.

so that would make the code like this:

 Here is part of my actual code, if that makes any difference.

 $password // this var was retrieved from db
 $int_id // this var was retrieved from db

 $file_array = file($DOCUMENT_ROOT/dir/file.dat);
 $count = count($file_array);
 if ($count == 0)
 echo pNo records found in .dat file./p;

 for ($i = 0; $i  $count; $i++)
 {
$temp_pass = trim(substr($file_array[$i], 13, 8));
$temp_int_id = trim(substr, $file_array[$i], 21, 4));
if ($temp_pass == $password  $temp_int_id == $int_id)
 {
 // do stuff
 }
 }


 Zach

 -Original Message-
 From: Edward van Bilderbeek - Bean IT [mailto:[EMAIL PROTECTED]]
 Sent: Friday, January 25, 2002 10:29 AM
 To: Zach Curtis
 Subject: Re: [PHP] Reg Exp Help


 but if the positions as fixed, why don't you use the substr, and then trim
 th result?

 Edward

 - Original Message -
 From: Zach Curtis [EMAIL PROTECTED]
 To: Edward van Bilderbeek - Bean IT [EMAIL PROTECTED]
 Cc: [EMAIL PROTECTED]
 Sent: Friday, January 25, 2002 6:12 PM
 Subject: RE: [PHP] Reg Exp Help


  The password and int_id begin and end in fixed positions.
 
  password begins in position 13 and can occupy up to 8 characters
  int_id begins in position 21 and can occupy up to 4 characters
 
  Sometimes a password (or int_id) may occupy all of those fixed position
or
  only some of the fixed positions, it's variable.
 
 
  Zach
 
  -Original Message-
  From: Edward van Bilderbeek - Bean IT [mailto:[EMAIL PROTECTED]]
  Sent: Friday, January 25, 2002 9:58 AM
  To: Zach Curtis
  Subject: Re: [PHP] Reg Exp Help
 
 
  how can I see that it isn't a 6 char $password with a 3 char $int_id ??
 
   This one has a 8 character $password, followed by zero white spaces,
   followed by a single character $int_id
   7d2ad345b
 
  Edward
 
 
  - Original Message -
  From: Zach Curtis [EMAIL PROTECTED]
  To: [EMAIL PROTECTED]
  Sent: Friday, January 25, 2002 5:51 PM
  Subject: [PHP] Reg Exp Help
 
 
   I am trying to code a regular expression that will match at the
 beginning
  of
   the string the contents of $password, followed by 0 or more
occurrences
 of
   white space, followed by the contents of $int_id. The match should be
 case
   insensitive.
  
   Here are some examples of the strings:
  
   This one has a 6 character $password, followed by two white spaces,
  followed
   by a single character $int_id
   9a9b9c  z
  
   This one has a 8 character $password, followed by zero white spaces,
   followed by a single character $int_id
   7d2ad345b
  
   This one has a 5 character $password, followed by three white spaces,
   followed by a four character $int_id
   d22ad   bbaw
  
  
   Here is the regular expression I am trying to use that does not find
the
   match and produces Warning: REG_BADRPT.
  
   (eregi(^\$password+[[:space:]]*+\$int_id, $file_array[$i]))
  
   Any corrections? Thanks in advance.
  
  
   Zach Curtis
   POPULUS
  
  
   --
   PHP General Mailing List (http://www.php.net/)
   To unsubscribe, e-mail: [EMAIL PROTECTED]
   For additional commands, e-mail: [EMAIL PROTECTED]
   To contact the list administrators, e-mail:
[EMAIL PROTECTED]
  
 
 
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  To contact the list administrators, e-mail: [EMAIL PROTECTED]
 






-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Reg. Exp. Help

2001-02-12 Thread Scott Mebberson

I really need help with this.

 I have written a regular expression that searches for any occurance of
 src="*" in a html page and rewrites it so that it is equal to
 src="http://www.whereever.com/images/filename.jpg" -

 If there are five occurances of this match then it replaces them all. Is
 there anyway to make it only run once. Then if I want to loop and do it
 again. I want to do this so I can put the contents of the original * in
 src="*" into and array and access them later for uploading the files.

I think that maybe preg_match() or preg_match_all() is the answer but I have
know idea on how to make the regular expression I am using perl comptaible.

Here it is:
$txt = ereg_replace("src=\"([^]+)\.(gif|jpg)\"",
"src=\"http://www.ezigraphics.com/images/about_0001." . //2. "\"", $txt);

Any ideas is a huge help - thankyou

 Thanks

 Scott Mebberson
[EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]