[PHP] Re: regular expression help!

2007-01-18 Thread Al

First stripslashes() and all newlines [\n\r*]. It makes the regex much easier.

$pattern= %img\x20[\w\d\=\x20]+(src=\x20*\)([/\w\d\.]+)[\\x20]*/%i;

preg_match($pattern, $string, $match); If more than one in the string, use 
preg_match_all().


Now print_r($match); so you can see the result.

Now, read the doc and see why each term is used. Note, I assumed your string can 
have some variation and still be W3C compatible e.g., src=. and

src= , etc. You may need to be able to handle additional variations.

Al

William Stokes wrote:

Hello,

Can someone here give me a glue how to do the following. I guess I need to 
use regular expressions here. I have absolutely zero experience with regular 
expressions. (if there's another way to do this I don't mind. I jus need to 
get this done somehow :)


I need to strip all characters from the following text string exept the 
image path...


img width=\99\ height=\120\ border=\0\ 
src=\../../images/new/thumps/4123141112007590373240.jpg\ /...and then 
store the path to DB. Image path lengh can vary so I guess that I need to 
extract all characters after scr=\until next\or somethig 
similar.


Thanks for your advise!
-Will


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



[PHP] Re: regular expression help

2005-01-21 Thread Jason
Jason wrote:
Simple functions to check  fix if necessary invalid formating of a MAC 
address... I seem to be having problems with the global variable $mac 
not being returned from the fix_mac() function.  Any help is appreciated.

?php
/*
 * ex. 00:AA:11:BB:22:CC
 */
function chk_mac( $mac ) {
global $mac;
 if( eregi( 
^[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}$, 
$mac ) ) {
  return 0;
 } else {
  return 1;
 }
}

/*
 * check validity of MAC  do replacements if necessary
 */
function fix_mac( $mac ) {
 global $mac;
 /* strip the dash  replace with a colon */
 if( eregi( 
^[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}$, 
$mac ) ) {
  $mac = preg_replace( /\-/, :, $mac );
  return $mac;
 }
 /* add a colon for every two characters */
 if( eregi( ^[0-9A-Fa-f]{12}$, $mac ) ) {
  /* split up the MAC and assign new var names */
  @list( $mac1, $mac2, $mac3, $mac4, $mac5, $mac6 ) = @str_split( $mac, 
2 );
  /* put it back together with the required colons */
  $mac = $mac1 . : . $mac2 . : . $mac3 . : . $mac4 . : . $mac5 . 
: . $mac6;
  return $mac;
 }
}

// do our checks to make sure we are using these damn things right
$mac1 = 00aa11bb22cc;
$mac2 = 00-aa-11-bb-22-cc;
$mac3 = 00:aa:11:bb:22:cc;
// make sure it is global
global $mac;
// if mac submitted is invalid check  fix if necessary
if( chk_mac( $mac1 ) != 0 ) {
 $mac = fix_mac( $mac1 ); echo $mac1 .  converted to  . $mac . br;
}
if( chk_mac( $mac2 ) != 0 ) {
 $mac = fix_mac( $mac2 ); echo $mac2 .  converted to  . $mac . br;
}
if( chk_mac( $mac3 ) != 0 ) {
 $mac = fix_mac( $mac3 ); echo $mac3 .  converted to  . $mac . br;
}
?
Still does not resolve the problem.  declaring $mac as global in the 
chk_mac() function.

--
Jason Gerfen
Student Computing
Marriott Library
801.585.9810
[EMAIL PROTECTED]
And remember... If the ladies
 don't find you handsome, they
 should at least find you handy...
 ~The Red Green show
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: regular expression help

2005-01-21 Thread RaTT
Hi, 

From what i can see you dont even need to call global, as your passing
variables to the function ? this could be causing the script to
confuse itself.

hth


On Fri, 21 Jan 2005 09:30:21 -0700, Jason [EMAIL PROTECTED] wrote:
 Jason wrote:
  Simple functions to check  fix if necessary invalid formating of a MAC
  address... I seem to be having problems with the global variable $mac
  not being returned from the fix_mac() function.  Any help is appreciated.
 
  ?php
  /*
   * ex. 00:AA:11:BB:22:CC
   */
  function chk_mac( $mac ) {
  global $mac;
   if( eregi(
  ^[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}$,
  $mac ) ) {
return 0;
   } else {
return 1;
   }
  }
 
  /*
   * check validity of MAC  do replacements if necessary
   */
  function fix_mac( $mac ) {
   global $mac;
   /* strip the dash  replace with a colon */
   if( eregi(
  ^[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}$,
  $mac ) ) {
$mac = preg_replace( /\-/, :, $mac );
return $mac;
   }
   /* add a colon for every two characters */
   if( eregi( ^[0-9A-Fa-f]{12}$, $mac ) ) {
/* split up the MAC and assign new var names */
@list( $mac1, $mac2, $mac3, $mac4, $mac5, $mac6 ) = @str_split( $mac,
  2 );
/* put it back together with the required colons */
$mac = $mac1 . : . $mac2 . : . $mac3 . : . $mac4 . : . $mac5 .
  : . $mac6;
return $mac;
   }
  }
 
  // do our checks to make sure we are using these damn things right
  $mac1 = 00aa11bb22cc;
  $mac2 = 00-aa-11-bb-22-cc;
  $mac3 = 00:aa:11:bb:22:cc;
 
  // make sure it is global
  global $mac;
 
  // if mac submitted is invalid check  fix if necessary
  if( chk_mac( $mac1 ) != 0 ) {
   $mac = fix_mac( $mac1 ); echo $mac1 .  converted to  . $mac . br;
  }
  if( chk_mac( $mac2 ) != 0 ) {
   $mac = fix_mac( $mac2 ); echo $mac2 .  converted to  . $mac . br;
  }
  if( chk_mac( $mac3 ) != 0 ) {
   $mac = fix_mac( $mac3 ); echo $mac3 .  converted to  . $mac . br;
  }
 
  ?
 Still does not resolve the problem.  declaring $mac as global in the
 chk_mac() function.
 
 --
 Jason Gerfen
 Student Computing
 Marriott Library
 801.585.9810
 [EMAIL PROTECTED]
 
 And remember... If the ladies
   don't find you handsome, they
   should at least find you handy...
   ~The Red Green show
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


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



[PHP] Re: regular expression help

2005-01-21 Thread Jason
You were right, I removed the reference to global $mac and it started 
working great.  Thanks.  It seems sometimes another set of eyes to catch 
stuff really helps... thanks.

Jason wrote:
Jason wrote:
Simple functions to check  fix if necessary invalid formating of a 
MAC address... I seem to be having problems with the global variable 
$mac not being returned from the fix_mac() function.  Any help is 
appreciated.

?php
/*
 * ex. 00:AA:11:BB:22:CC
 */
function chk_mac( $mac ) {
global $mac;
 if( eregi( 
^[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}$, 
$mac ) ) {
  return 0;
 } else {
  return 1;
 }
}

/*
 * check validity of MAC  do replacements if necessary
 */
function fix_mac( $mac ) {
 global $mac;
 /* strip the dash  replace with a colon */
 if( eregi( 
^[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}$, 
$mac ) ) {
  $mac = preg_replace( /\-/, :, $mac );
  return $mac;
 }
 /* add a colon for every two characters */
 if( eregi( ^[0-9A-Fa-f]{12}$, $mac ) ) {
  /* split up the MAC and assign new var names */
  @list( $mac1, $mac2, $mac3, $mac4, $mac5, $mac6 ) = @str_split( 
$mac, 2 );
  /* put it back together with the required colons */
  $mac = $mac1 . : . $mac2 . : . $mac3 . : . $mac4 . : . $mac5 
. : . $mac6;
  return $mac;
 }
}

// do our checks to make sure we are using these damn things right
$mac1 = 00aa11bb22cc;
$mac2 = 00-aa-11-bb-22-cc;
$mac3 = 00:aa:11:bb:22:cc;
// make sure it is global
global $mac;
// if mac submitted is invalid check  fix if necessary
if( chk_mac( $mac1 ) != 0 ) {
 $mac = fix_mac( $mac1 ); echo $mac1 .  converted to  . $mac . br;
}
if( chk_mac( $mac2 ) != 0 ) {
 $mac = fix_mac( $mac2 ); echo $mac2 .  converted to  . $mac . br;
}
if( chk_mac( $mac3 ) != 0 ) {
 $mac = fix_mac( $mac3 ); echo $mac3 .  converted to  . $mac . br;
}
?
Still does not resolve the problem.  declaring $mac as global in the 
chk_mac() function.


--
Jason Gerfen
And remember... If the ladies
 don't find you handsome, they
 should at least find you handy...
 ~The Red Green show
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Regular expression help?

2004-02-02 Thread Matthew Weier O'Phinney
* Jas [EMAIL PROTECTED]:
 Not sure if anyone knows of a good way to match strings of this type...
 00:02:8b:0c:2f:09

 I have tried this but its not working.

 !eregi(^[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}$,$_POST['mac'])

Use the perl compatible regexps instead:

!preg_match('/^([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$/', $_POST['mac'])

This searches for XX: 5 followed by XX, where XX is 0-9, A-F, or a-f. I
_think_ the POSIX regexps can do some grouping like this as well, but
I'm not absolutely sure.

-- 
Matthew Weier O'Phinney
Webmaster and IT Specialist
National Gardening Association
802-863-5251 x156
mailto:[EMAIL PROTECTED]
http://www.garden.org
http://www.kidsgardening.com

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



[PHP] Re: Regular Expression Help in my PHP! Sorry if wrong group

2003-01-15 Thread Jason Lehman
I figured out what I was doing wrong.  My regexp should of looked like 
this /a[^]*(Tampa)\/a/ and that made it more specific and kept it 
to that match.

Jason Lehman wrote:
I have a script that turns certain words into links.  That I am having 
no problems with, it is when I want to turn the links back in to plain 
text that I am having the problem.  Below are my examples.  And I know 
my regex is being greedy but I don't know how to stop it from being so 
damn greedy I thought the ? mark would help but it didn't. Any help 
would be appreciated. So here it goes:


The code:

$strStr = This is a href=testUSF/a at a href=testTampa/a.  This 
is a href=testUSF/a at a href=testTampa/a.;
echo $strStr.br\n;
$strStr = preg_replace(/a.*?(Tampa)\/a/,\\1,$strStr);
echo $strStr.br\n;
$strStr = preg_replace(/a.*?(USF)\/a/,\\1,$strStr);
echo $strStr.br\n;

The output:

This is a href=testUSF/a at a href=testTampa/a. This is a 
href=testUSF/a at a href=testTampa/a.
This is Tampa. This is Tampa.
This is Tampa. This is Tampa.

The expected output:

This is a href=testUSF/a at a href=testTampa/a. This is a 
href=testUSF/a at a href=testTampa/a.
This is a href=testUSF/a at Tampa. This is a href=testUSF/a at 
Tampa.
This is USF at Tampa. This is USF at Tampa.



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




[PHP] Re: regular expression help

2001-09-18 Thread _lallous

This should do (but ofcourse you might want to play a bit with it)

$mem =
'
A HREF=http://www.mydomain.com/mypage.php;something/a is fine
A HREF=http://www.yourdomain.com/yourpage.php;something/a is wrong
A HREF=http://www.yourdomain.com/yourpage.php;something/a is finebr
a href=http://www.lgwm.org/;lgwm/abr
a href=http://www.google.com;
onclick=javascript:alert(\'hello\');Google!/a
';

function handler($theTag, $theDomain)
{
  if (!strstr($theDomain, mydomain.com))
  {
$theTag = strstr($theTag,  );
$theTag = a target='_blank'$theTag;
  }
  return stripslashes($theTag);
}

$re = /\s*a\s*href\s*=\s*(['\])(.+?)\\1[^]*/eis;
$t = preg_replace($re, handler('\\0', '\\2') ,$mem);
echo $t;

//greetings RZe!

Justin French [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 hi all,

 I have some user-supplied text on a content driven site.
 I am allowing A tags inside the main text, BUT I want
 any links to external sites (not on the chosen domain)
 to include a ' TARGET=_new ' element.

 So,

 A HREF=http://www.mydomain.com/mypage.php;something/a is fine
 A HREF=http://www.yourdomain.com/yourpage.php;something/a is wrong
 A HREF=http://www.yourdomain.com/yourpage.php;
 TARGET=_newsomething/a is fine

 And of course there are all the variants with and without
 the www, and with and without sub directories and pages.

 I'[d also like to make sure the dopey people have put a
 close tag in.


 I've got a few ideas on how it might be done, but I need
 to do it the right way, avoiding slight human errors etc.


 Has anyone got something written, or can point me in the
 right direction?


 Justin French



-- 
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] Re: Regular Expression help

2001-06-30 Thread J Smith

Clayton Dukes wrote:

 Okay, here's what I have so far:
 
 ---snip---
 if ((!$email)
|| ($email==)
|| (!eregi(^[_\.0-9a-z-]+@domain.+[a-z],$email))
)
 $stop = center._ERRORINVEMAIL./centerbr;
 ---snip---
 
 This works, but how can I add a second domain?
 ie:
 

Try:

^[_\.0-9a-z-]+@(domainA|domainB|etc)\.[a-z]{2,3}$

A complete email address check is insanely hard to to if you want to get 
RFC 822 compliant-checking, but who needs that anyways? (fwiw, the regex in 
Mastering Regular Expressions for checking email address syntax is some 
4,700 bytes long.)

J

-- 
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] Re: Regular Expression help

2001-06-30 Thread Brad Hubbard

On Fri, 29 Jun 2001 23:43, Clayton Dukes wrote:
 Okay, here's what I have so far:

 ---snip---
 if ((!$email)

|| ($email==)
|| (!eregi(^[_\.0-9a-z-]+@domain.+[a-z],$email))

)
 $stop = center._ERRORINVEMAIL./centerbr;
 ---snip---

 This works, but how can I add a second domain?

How 'bout;

---snip---
 if ((!$email)
|| ($email==)
|| (!eregi(^[_\.0-9a-z-]+@domain|otherdomain.+[a-z],$email)

)
 $stop = center._ERRORINVEMAIL./centerbr;
---snip---

Cheers,
Brad
-- 
Brad Hubbard
Congo Systems
12 Northgate Drive,
Thomastown, Victoria, Australia 3074
Email: [EMAIL PROTECTED]
Ph: +61-3-94645981
Fax: +61-3-94645982
Mob: +61-419107559

-- 
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] Re: Regular Expression help

2001-06-29 Thread Clayton Dukes

Okay, here's what I have so far:

---snip---
if ((!$email)
   || ($email==)
   || (!eregi(^[_\.0-9a-z-]+@domain.+[a-z],$email))
   )
$stop = center._ERRORINVEMAIL./centerbr;
---snip---

This works, but how can I add a second domain?
ie:

---snip---
if ((!$email)
   || ($email==)
   || (!eregi(^[_\.0-9a-z-]+@domain.+[a-z],$email))
   || (!eregi(^[_\.0-9a-z-]+@otherdomain.+[a-z],$email))
   )
$stop = center._ERRORINVEMAIL./centerbr;
---snip---

This doesn't work. (it returns the error no matter what I enter)

Thanks guys (and gals?)

Clayton Dukes
CCNA, CCDA, CCDP, CCNP
Download Free Essays, Term Papers and Cisco Training from http://www.gdd.net


- Original Message -
From: Clayton Dukes [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, June 29, 2001 9:08 AM
Subject: Regular Expression help


 Hi everyone,

 I have a new user function that checks e-mail addresses.
 I wish to only allow people from two different domains to register.
 How can I filter out all other e-mail addresses and return an error if
it's
 not from those domains.

 Here's what I have:

 if ((!$email) || ($email==) ||
 (!eregi(^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$,$email)))
$stop
 = center._ERRORINVEMAIL./centerbr;

 What this currently does is just makes sure it's a valid e-mail address.
 What I'd like it to do is if the user enters anything except @domain1.com
or
 @domain2.com it spits out the error (ERRORINVEMAIL)

 So (I think) It would look something like this:

 if ((!$email) || ($email==) || (!eregi(^[_\.0-9a-z-]+@([DdOoMmAaIiNn1]
||
 (or statement???) [DdOoMmAaIiNn2-]+\.)+[a-z]{2,3}$,$email))) $stop =
 center._ERRORINVEMAIL./centerbr;


 Of course, this doesn't work, but you get the point.


 Thanks!
 P.S.
 Thanks for the Awesome List!

 Clayton Dukes
 CCNA, CCDA, CCDP, CCNP
 Download Free Essays, Term Papers and Cisco Training from
http://www.gdd.net






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