Re: [PHP] Regular Expression help need
Before: phi strongRichard/strong, good morninglt;/p After: phi strongRichard/stronggt;, amp; good morninglt;/p By the sounds of it negative look ahead assertions may be of some help. Or look behind assertions. -- Richard Heyes http://www.phpguru.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular Expression help need
On Fri, Jul 25, 2008 at 1:08 PM, Shelley [EMAIL PROTECTED] wrote: Hi Richard, Not exactly actually. What I mean is: Before: phi strongRichard/strong, good morninglt;/p After: phi strongRichard/stronggt;, amp; good morninglt;/p I hope it's clear now. On Fri, Jul 25, 2008 at 7:53 PM, Richard Heyes [EMAIL PROTECTED] wrote: How can I make a string with (NOT amp;, gt;, lt; or quot;), , xml compatible? What is the expression to use? Not entirely sure what you're after (try posting some before and after snippets), but by the sounds of it you don't need a regular expression - strtr() will work for you. Or str_replace(). -- Richard Heyes http://www.phpguru.org -- Regards, Shelley Is it possible for you to use a mixture of html_entity_decode, htmlentities e.g. ?php $content = html_entity_decode(', good morninglt;'); echo 'phi strongRichard/strong'.htmlentities($content).'/p'; /James
Re: [PHP] Regular Expression help need
Are you talking about looking at blogs in a mobile phone browser or actually downloading the blog into another format? Thank you, Micah Gersten onShore Networks Internal Developer http://www.onshore.com Shelley wrote: Ok, let me tell you what i want to achieve. I want to transfer users' blog onto mobile phone, so I should convert characters such as , , (but not amp;, or gt;, or lt;, etc) into xml compatible ones, gt;, lt; amp;. Maybe there is some problem in my expression? Waiting for your response... On Sat, Jul 26, 2008 at 3:30 AM, Micah Gersten [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Are you trying to make it xml compatible or XHTML compatible? '' is not valid HTML or XHTML as it has special meaning. If you want it to adhere to the standard and display correctly, you must use 'amp;' Thank you, Micah Gersten onShore Networks Internal Developer http://www.onshore.com Shelley wrote: Hi Richard, Not exactly actually. What I mean is: Before: phi strongRichard/strong, good morninglt;/p After: phi strongRichard/stronggt;, amp; good morninglt;/p I hope it's clear now. On Fri, Jul 25, 2008 at 7:53 PM, Richard Heyes [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: How can I make a string with (NOT amp;, gt;, lt; or quot;), , xml compatible? What is the expression to use? Not entirely sure what you're after (try posting some before and after snippets), but by the sounds of it you don't need a regular expression - strtr() will work for you. Or str_replace(). -- Richard Heyes http://www.phpguru.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- With best regards, Shelley Shyan http://phparch.cn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regular Expression help need
Hi all, How can I make a string with (NOT amp;, gt;, lt; or quot;), , xml compatible? What is the expression to use? Thank you very much. -- Regards, Shelley
Re: [PHP] Regular Expression help need
How can I make a string with (NOT amp;, gt;, lt; or quot;), , xml compatible? What is the expression to use? Not entirely sure what you're after (try posting some before and after snippets), but by the sounds of it you don't need a regular expression - strtr() will work for you. Or str_replace(). -- Richard Heyes http://www.phpguru.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular Expression help need
Hi Richard, Not exactly actually. What I mean is: Before: phi strongRichard/strong, good morninglt;/p After: phi strongRichard/stronggt;, amp; good morninglt;/p I hope it's clear now. On Fri, Jul 25, 2008 at 7:53 PM, Richard Heyes [EMAIL PROTECTED] wrote: How can I make a string with (NOT amp;, gt;, lt; or quot;), , xml compatible? What is the expression to use? Not entirely sure what you're after (try posting some before and after snippets), but by the sounds of it you don't need a regular expression - strtr() will work for you. Or str_replace(). -- Richard Heyes http://www.phpguru.org -- Regards, Shelley
Re: [PHP] Regular Expression help need
Are you trying to make it xml compatible or XHTML compatible? '' is not valid HTML or XHTML as it has special meaning. If you want it to adhere to the standard and display correctly, you must use 'amp;' Thank you, Micah Gersten onShore Networks Internal Developer http://www.onshore.com Shelley wrote: Hi Richard, Not exactly actually. What I mean is: Before: phi strongRichard/strong, good morninglt;/p After: phi strongRichard/stronggt;, amp; good morninglt;/p I hope it's clear now. On Fri, Jul 25, 2008 at 7:53 PM, Richard Heyes [EMAIL PROTECTED] wrote: How can I make a string with (NOT amp;, gt;, lt; or quot;), , xml compatible? What is the expression to use? Not entirely sure what you're after (try posting some before and after snippets), but by the sounds of it you don't need a regular expression - strtr() will work for you. Or str_replace(). -- Richard Heyes http://www.phpguru.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular Expression help need
Ok, let me tell you what i want to achieve. I want to transfer users' blog onto mobile phone, so I should convert characters such as , , (but not amp;, or gt;, or lt;, etc) into xml compatible ones, gt;, lt; amp;. Maybe there is some problem in my expression? Waiting for your response... On Sat, Jul 26, 2008 at 3:30 AM, Micah Gersten [EMAIL PROTECTED] wrote: Are you trying to make it xml compatible or XHTML compatible? '' is not valid HTML or XHTML as it has special meaning. If you want it to adhere to the standard and display correctly, you must use 'amp;' Thank you, Micah Gersten onShore Networks Internal Developer http://www.onshore.com Shelley wrote: Hi Richard, Not exactly actually. What I mean is: Before: phi strongRichard/strong, good morninglt;/p After: phi strongRichard/stronggt;, amp; good morninglt;/p I hope it's clear now. On Fri, Jul 25, 2008 at 7:53 PM, Richard Heyes [EMAIL PROTECTED] wrote: How can I make a string with (NOT amp;, gt;, lt; or quot;), , xml compatible? What is the expression to use? Not entirely sure what you're after (try posting some before and after snippets), but by the sounds of it you don't need a regular expression - strtr() will work for you. Or str_replace(). -- Richard Heyes http://www.phpguru.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- With best regards, Shelley Shyan http://phparch.cn
[PHP] regular expression help!
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
Re: [PHP] regular expression help!
# [EMAIL PROTECTED] / 2007-01-18 12:34:36 +0200: 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. This passes with 5.2: class ImgSrcTest extends Tence_TestCase { private $src, $str, $xml; function setUp() { $this-src = 'fubar.jpg'; $this-str = sprintf( 'img width=99 height=120 border=0 src=%s /', $this-src ); $this-xml = new SimpleXmlElement($this-str); } function testReturnsAttributeAsSimpleXMLElements() { return $this-assertEquals('SimpleXMLElement', get_class($this-xml['src'])); } function testCastToStringYieldsTheAttributeValue() { return $this-assertEquals($this-src, strval($this-xml['src'])); } } -- How many Vietnam vets does it take to screw in a light bulb? You don't know, man. You don't KNOW. Cause you weren't THERE. http://bash.org/?255991 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regular expression help!
Hello Roman, Could you specify the functionality of your script a bit please. (How it works) I forgot to mention that this part: img width=99 height=120 border=0 src=%s /', is not always the same. The image properties can vary. Thanks -Will Roman Neuhauser [EMAIL PROTECTED] kirjoitti viestissä:[EMAIL PROTECTED] # [EMAIL PROTECTED] / 2007-01-18 12:34:36 +0200: 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. This passes with 5.2: class ImgSrcTest extends Tence_TestCase { private $src, $str, $xml; function setUp() { $this-src = 'fubar.jpg'; $this-str = sprintf( 'img width=99 height=120 border=0 src=%s /', $this-src ); $this-xml = new SimpleXmlElement($this-str); } function testReturnsAttributeAsSimpleXMLElements() { return $this-assertEquals('SimpleXMLElement', get_class($this-xml['src'])); } function testCastToStringYieldsTheAttributeValue() { return $this-assertEquals($this-src, strval($this-xml['src'])); } } -- How many Vietnam vets does it take to screw in a light bulb? You don't know, man. You don't KNOW. Cause you weren't THERE. http://bash.org/?255991 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regular expression help!
William Stokes wrote: Hello Roman, Could you specify the functionality of your script a bit please. (How it works) it's a hint as to how you might use simpleXML to extract the values of a src attribute from the definition of an img tag. I forgot to mention that this part: img width=99 height=120 border=0 src=%s /', is not always the same. The image properties can vary. Thanks -Will Roman Neuhauser [EMAIL PROTECTED] kirjoitti viestissä:[EMAIL PROTECTED] # [EMAIL PROTECTED] / 2007-01-18 12:34:36 +0200: 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. This passes with 5.2: class ImgSrcTest extends Tence_TestCase { private $src, $str, $xml; function setUp() { $this-src = 'fubar.jpg'; $this-str = sprintf( 'img width=99 height=120 border=0 src=%s /', $this-src ); $this-xml = new SimpleXmlElement($this-str); } function testReturnsAttributeAsSimpleXMLElements() { return $this-assertEquals('SimpleXMLElement', get_class($this-xml['src'])); } function testCastToStringYieldsTheAttributeValue() { return $this-assertEquals($this-src, strval($this-xml['src'])); } } -- How many Vietnam vets does it take to screw in a light bulb? You don't know, man. You don't KNOW. Cause you weren't THERE. http://bash.org/?255991 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regular expression help!
(Haven't received William's email yet = scavenging Jochem's reply.) # [EMAIL PROTECTED] / 2007-01-18 18:01:19 +0100: William Stokes wrote: Roman Neuhauser [EMAIL PROTECTED] kirjoitti This passes with 5.2: class ImgSrcTest extends Tence_TestCase { private $src, $str, $xml; function setUp() { $this-src = 'fubar.jpg'; $this-str = sprintf( 'img width=99 height=120 border=0 src=%s /', $this-src ); $this-xml = new SimpleXmlElement($this-str); } function testReturnsAttributeAsSimpleXMLElements() { return $this-assertEquals( 'SimpleXMLElement', get_class($this-xml['src']) ); } function testCastToStringYieldsTheAttributeValue() { return $this-assertEquals($this-src, strval($this-xml['src'])); } } Could you specify the functionality of your script a bit please. (How it works) It's a unit test showing how you can use SimpleXML to do what you want. It's written for Testilence out of sheer laziness, but any unit testing tool would do (after cosmetic changes to the code). The test case contains two pretty obvious tests, just read the function names, their bodies should be pretty obvious. On thing that might be a little non-obvious is the strval(): that was the only way I found to get the string out of the very uncommunicative SimpleXMLElement. I forgot to mention that this part: img width=99 height=120 border=0 src=%s /', is not always the same. The image properties can vary. That's one of the reasons I didn't go the regexp route. Don't treat XML as text, it's not. -- How many Vietnam vets does it take to screw in a light bulb? You don't know, man. You don't KNOW. Cause you weren't THERE. http://bash.org/?255991 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regular Expression help
?php echo 'Is String: [' . ( is_string( 'a1b2c3' ) preg_match( '/[A-Za-z]+/', 'a1b2c3' )) . ']br'; echo 'Is Numeric: [' . ( is_numeric( 'a1b2c3' ) preg_match( '/[0-9]+/', 'a1b2c3' )) . ']br'; echo 'Is String: [' . ( is_string( 'abcdef' ) preg_match( '/[A-Za-z]+/', 'abcdef' )) . ']br'; echo 'Is Numeric: [' . ( is_numeric( '123456' ) preg_match( '/[0-9]+/', '123456' )) . ']br'; ? Why is the first Is String check returning true/showing 1? preg_match should fail because 'a1b2c3' contains numbers and, as such, doesn't match the pattern... What am I doing wrong? thnx, Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular Expression help
Those patterns aren't anchored to the ends of the string, so as long as the string contains one matching character, the succeeds. ^ anchors the pattern to the beginning, \z to the end, so you want: /^[A-Za-z]+\z/ Or test the opposite case to see if it fails: /[^A-Za-z]/ Arpad Chris Boget wrote: ?php echo 'Is String: [' . ( is_string( 'a1b2c3' ) preg_match( '/[A-Za-z]+/', 'a1b2c3' )) . ']br'; echo 'Is Numeric: [' . ( is_numeric( 'a1b2c3' ) preg_match( '/[0-9]+/', 'a1b2c3' )) . ']br'; echo 'Is String: [' . ( is_string( 'abcdef' ) preg_match( '/[A-Za-z]+/', 'abcdef' )) . ']br'; echo 'Is Numeric: [' . ( is_numeric( '123456' ) preg_match( '/[0-9]+/', '123456' )) . ']br'; ? Why is the first Is String check returning true/showing 1? preg_match should fail because 'a1b2c3' contains numbers and, as such, doesn't match the pattern... What am I doing wrong? thnx, Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular Expression help
Chris Boget wrote: ?php echo 'Is String: [' . ( is_string( 'a1b2c3' ) preg_match( '/[A-Za-z]+/', 'a1b2c3' )) . ']br'; echo 'Is Numeric: [' . ( is_numeric( 'a1b2c3' ) preg_match( '/[0-9]+/', 'a1b2c3' )) . ']br'; echo 'Is String: [' . ( is_string( 'abcdef' ) preg_match( '/[A-Za-z]+/', 'abcdef' )) . ']br'; echo 'Is Numeric: [' . ( is_numeric( '123456' ) preg_match( '/[0-9]+/', '123456' )) . ']br'; ? Why is the first Is String check returning true/showing 1? preg_match should fail because 'a1b2c3' contains numbers and, as such, doesn't match the pattern... It does match the pattern. The expression says 1 or more A-Za-z in sequence. If you want to check against the whole string you need to add the start and end markers... preg_match( '/^[A-Za-z]+$/', 'a1b2c3' )) Look at the manual page for preg_match and read up on the third parameter. Use it to see what is matching the expression. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular Expression help
Note that $ allows a trailing newline, but \z doesn't. Arpad Stut wrote: Chris Boget wrote: ?php echo 'Is String: [' . ( is_string( 'a1b2c3' ) preg_match( '/[A-Za-z]+/', 'a1b2c3' )) . ']br'; echo 'Is Numeric: [' . ( is_numeric( 'a1b2c3' ) preg_match( '/[0-9]+/', 'a1b2c3' )) . ']br'; echo 'Is String: [' . ( is_string( 'abcdef' ) preg_match( '/[A-Za-z]+/', 'abcdef' )) . ']br'; echo 'Is Numeric: [' . ( is_numeric( '123456' ) preg_match( '/[0-9]+/', '123456' )) . ']br'; ? Why is the first Is String check returning true/showing 1? preg_match should fail because 'a1b2c3' contains numbers and, as such, doesn't match the pattern... It does match the pattern. The expression says 1 or more A-Za-z in sequence. If you want to check against the whole string you need to add the start and end markers... preg_match( '/^[A-Za-z]+$/', 'a1b2c3' )) Look at the manual page for preg_match and read up on the third parameter. Use it to see what is matching the expression. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular Expression help
Arpad Ray wrote: Note that $ allows a trailing newline, but \z doesn't. I had to test that before believing you: php -r 'var_dump(preg_match(#^[a-z]+\$#,abc),preg_match(#^[a-z]+\$#,abc\n),preg_match(#^[a-z]+\z#,abc\n));' you are right, that could consitute a nice big gotcha in some situations, although I have the habit of running trim on everything bit of data that has to be validated/santized (prior to any more specific checks/cleansing) so I have been protecting my self unwittingly: php -r 'var_dump(abc\n, trim(abc\n));' none the less I think I'll be using \z more often now that I have been properly introduced to it (including answering any regexp questions around here!) thanks Arpad :-) Arpad Stut wrote: Chris Boget wrote: ?php echo 'Is String: [' . ( is_string( 'a1b2c3' ) preg_match( '/[A-Za-z]+/', 'a1b2c3' )) . ']br'; echo 'Is Numeric: [' . ( is_numeric( 'a1b2c3' ) preg_match( '/[0-9]+/', 'a1b2c3' )) . ']br'; echo 'Is String: [' . ( is_string( 'abcdef' ) preg_match( '/[A-Za-z]+/', 'abcdef' )) . ']br'; echo 'Is Numeric: [' . ( is_numeric( '123456' ) preg_match( '/[0-9]+/', '123456' )) . ']br'; ? Why is the first Is String check returning true/showing 1? preg_match should fail because 'a1b2c3' contains numbers and, as such, doesn't match the pattern... It does match the pattern. The expression says 1 or more A-Za-z in sequence. If you want to check against the whole string you need to add the start and end markers... preg_match( '/^[A-Za-z]+$/', 'a1b2c3' )) Look at the manual page for preg_match and read up on the third parameter. Use it to see what is matching the expression. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regular Expression help
I've been beating my head against the wall for a while trying to come up with the RE I need to use. I have a camel case word - let's use JimJoeBobBriggs. I need to come up with a RE that will fine all the upper case characters and insert an underscore prior to those characters with the exception of a possible first character. So using the aforementioned word, the RE would change it to Jim_Joe_Bob_Briggs. Any help would be greatly appreciated! thnx, Chris
Re: [PHP] Regular Expression help
Chris Boget wrote: I've been beating my head against the wall for a while trying to come up with the RE I need to use. I have a camel case word - let's use JimJoeBobBriggs. I need to come up with a RE that will fine all the upper case characters and insert an underscore prior to those characters with the exception of a possible first character. So using the aforementioned word, the RE would change it to Jim_Joe_Bob_Briggs. $result = preg_replace('#(.)([A-Z])#', '\1_\2', 'JimJoeBobBriggs'); -- Richard Heyes http://www.phpguru.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular Expression help
On 1/19/06, Chris Boget [EMAIL PROTECTED] wrote: I've been beating my head against the wall for a while trying to come up with the RE I need to use. I have a camel case word - let's use JimJoeBobBriggs. I need to come up with a RE that will fine all the upper case characters and insert an underscore prior to those characters with the exception of a possible first character. So using the aforementioned word, the RE would change it to Jim_Joe_Bob_Briggs. ?php $string = 'JimJoeBobBriggs''; print preg_replace('/([[:alnum:]])([[:upper:]])/', '\1_\2', $string); ?
Re: [PHP] Regular Expression help
Chris Boget wrote: I've been beating my head against the wall for a while trying to come up with the RE I need to use. I have a camel case word - let's use JimJoeBobBriggs. I need to come up with a RE that will fine all the upper case characters and insert an underscore prior to those characters with the exception of a possible first character. So using the aforementioned word, the RE would change it to Jim_Joe_Bob_Briggs. Any help would be greatly appreciated! thnx, Chris Those two had valid ones as well, but I like the negative look-behind assertion: preg_replace('/(?!^)([A-Z])/','_$1','JimJoeBobBriggs'); Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular Expression help
Chris Boget wrote: I've been beating my head against the wall for a while trying to come up with the RE I need to use. I have a camel case word - let's use JimJoeBobBriggs. I need to come up with a RE that will fine all the upper case characters and insert an underscore prior to those characters with the exception of a possible first character. So using the aforementioned word, the RE would change it to Jim_Joe_Bob_Briggs. Any help would be greatly appreciated! preg_replace ( /(.)([A-Z])/, \1_\2, $string ); -- John C. Nichel IV Programmer/System Admin (ÜberGeek) Dot Com Holdings of Buffalo 716.856.9675 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular Expression help
Chris wrote: snip preg_replace('/(?!^)([A-Z])/','_$1','JimJoeBobBriggs'); Ohhhregex-fu black belt. ;) -- John C. Nichel IV Programmer/System Admin (ÜberGeek) Dot Com Holdings of Buffalo 716.856.9675 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regular expression help
I just plain suck at regex, so I was hoping to get some hints from you regex experts out there. I'm sure it's been done a thousand times, but I can't seem to find what I'm looking for with a simple google search: $phone could be 1234567890 OR $phone could be 123-456-7890 OR $phone could be (123) 456 7890 OR $phone could have other unexpected characters in it, even control characters. So what I'm desiring to do is run some type of regex on $phone and only return the integers and assign the cleaned string back to $phone. I thought I knew how to do this, but it's not working. Thanks for your guidance. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular expression help
David Christensen wrote: I just plain suck at regex, so I was hoping to get some hints from you regex experts out there. I'm sure it's been done a thousand times, but I can't seem to find what I'm looking for with a simple google search: $phone could be 1234567890 OR $phone could be 123-456-7890 OR $phone could be (123) 456 7890 OR $phone could have other unexpected characters in it, even control characters. So what I'm desiring to do is run some type of regex on $phone and only return the integers and assign the cleaned string back to $phone. I thought I knew how to do this, but it's not working. Thanks for your guidance. If all you want is the digits $phone = preg_replace ( /\D/, , $phone ); Same as /[^0-9]/ -- John C. Nichel ÜberGeek KegWorks.com 716.856.9675 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] regular expression help
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 ) { 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; } ? -- 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
Re: [PHP] regular expression help
On Saturday 22 January 2005 00:12, 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. Your subject says regular expression help but your problem is with the global variable $mac So which is it? If you're going to declare a variable as 'global' then it has to be done in every function in which that variable is to be used. Which means here: function chk_mac( $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; } } and wherever else. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- New Year Resolution: Ignore top posted posts -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regular expression help
On Fri, 2005-01-21 at 10:12, 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 ) { 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 you want to use globals you need to use the global in the function not the main body. afaict you don't need globals at all you pass mac1 to each function and use it as $mac in the function (exactly what you want to do) and return local $mac to $mac in the main body. perfectly legal. If you set mac to global in the function I suspect that you end up not using the local mac and are testing an empty var in the first pass of fix_mac. remove the global statements and you are well on your way. Bret // 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; } ? -- 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 General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regular expression help
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. function fix_mac( $mac ) { global $mac; It's really weird to both pass in $mac as an argument and to declare it global... Do one or the other, but not both. Can't help you with the mess of Regex you've got though... -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regular expression help
Richard Lynch 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. function fix_mac( $mac ) { global $mac; It's really weird to both pass in $mac as an argument and to declare it global... Do one or the other, but not both. quite. Can't help you with the mess of Regex you've got though... now I bet you can actually, chicken and egg: you have to have the skill to recognise the mess. ;-) Jason - don't be dishearted: a, regexp are/can be hard b, anyone who is giving them a go, is probably trying hard to improve their skills (we like that :-)) - regexps are quite a hurdle for most people. c, we all start out writing regexps like yours (i.e. simple ones) and eventually they become more and more complex/arcane until you become Larry Wall. --- did someone say 'who is Larry Wall?'?, 10 lashes for that man -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regular expression help
On Wednesday 29 September 2004 08:46, Ed Lazor wrote: complain Today I discovered that my ISP can't upgrade to PHP 5. They use Plesk for server Administration and PHP 5 apparently breaks Plesk. Plesk says they'll make PHP 5 support available as soon as it starts coming default on RedHat Enterprise. /complain Unfortunately, I now have a bunch of scripts that require PHP 5. I'd upgraded my beta server for testing and everything has been going so great that I went gungho. Honestly, I tried to not too many of the new features, just so I could ease into it and do more testing. I'm finding little differences that I didn't even realize I was taking advantage of. For example, there are a lot of places in the code where I've done something like this: print Learn more about {$product-get_Title()}.br; http://www.php.net/manual/en/function.preg-replace.php $pattern = /\{\$(.+?)\}/i; $replacement = \\.\$$1\.\; Try this out ;-) I haven't tested it but it's the right direction ;-) I uploaded scripts like this to the production server for more testing and PHP4 flagged all of the code like this as parse errors. I'm not sure, but now I'm stuck having to go through all of the code to change the coding style my editor (Dreamweaver MX 2004) allows me to do a global search and replace using regular expressions. I have no idea what regular expression I'd use for something like this. Any recommendations? Thanks, Ed -- Cyberly yours, Petar Nedyalkov Devoted Orbitel Fan :-) - Orbitel - the New Generation Telecom! See www.orbitel.bg. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] regular expression help
Thanks to everyone who sent in patterns =) They worked like a charm =) $pattern = /\{\$(.+?)\}/i; $replacement = \\.\$$1\.\; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] regular expression help
complain Today I discovered that my ISP can't upgrade to PHP 5. They use Plesk for server Administration and PHP 5 apparently breaks Plesk. Plesk says they'll make PHP 5 support available as soon as it starts coming default on RedHat Enterprise. /complain Unfortunately, I now have a bunch of scripts that require PHP 5. I'd upgraded my beta server for testing and everything has been going so great that I went gungho. Honestly, I tried to not too many of the new features, just so I could ease into it and do more testing. I'm finding little differences that I didn't even realize I was taking advantage of. For example, there are a lot of places in the code where I've done something like this: print Learn more about {$product-get_Title()}.br; I uploaded scripts like this to the production server for more testing and PHP4 flagged all of the code like this as parse errors. I'm not sure, but now I'm stuck having to go through all of the code to change the coding style my editor (Dreamweaver MX 2004) allows me to do a global search and replace using regular expressions. I have no idea what regular expression I'd use for something like this. Any recommendations? Thanks, Ed -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regular expression help
Howdy, Regular expressions are a simple way of matching patters. You can learn more about regular expressions in general here: http://www.opengroup.org/onlinepubs/007908799/xbd/re.html If you are interested in using regular expressions in PHP, check out these sites: http://www.php.net/manual/en/reference.pcre.pattern.syntax.php http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php A regex to match what you are looking for would be /\{(.+?)\}/, and then just replace it without the { and } for the replace part. On Tue, 2004-09-28 at 22:46, Ed Lazor wrote: complain Today I discovered that my ISP can't upgrade to PHP 5. They use Plesk for server Administration and PHP 5 apparently breaks Plesk. Plesk says they'll make PHP 5 support available as soon as it starts coming default on RedHat Enterprise. /complain Unfortunately, I now have a bunch of scripts that require PHP 5. I'd upgraded my beta server for testing and everything has been going so great that I went gungho. Honestly, I tried to not too many of the new features, just so I could ease into it and do more testing. I'm finding little differences that I didn't even realize I was taking advantage of. For example, there are a lot of places in the code where I've done something like this: print Learn more about {$product-get_Title()}.br; I uploaded scripts like this to the production server for more testing and PHP4 flagged all of the code like this as parse errors. I'm not sure, but now I'm stuck having to go through all of the code to change the coding style my editor (Dreamweaver MX 2004) allows me to do a global search and replace using regular expressions. I have no idea what regular expression I'd use for something like this. Any recommendations? Thanks, Ed -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regular expression help
I'm trying to replace all occurances of the X character in a text with Y, but only those X's that occur between bold tags (b/b). -- Romanian Web Developers - http://ROWD.ORG -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular expression help
From: Skippy [EMAIL PROTECTED] I'm trying to replace all occurances of the X character in a text with Y, but only those X's that occur between bold tags (b/b). ?php $str = 'This X and this X will not be fixed, but bthis X and/b and hopefully this bX/b should be, along b with this X also. /b, but not this X.'; function myreplace($match) { $from = 'X'; $to = 'Y'; return str_replace($from,$to,$match[0]); } $new_str = preg_replace_callback('#b.*/b#Uis','myreplace',$str); echo $new_str; ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular expression help
Quoting John Holmes [EMAIL PROTECTED]: From: Skippy [EMAIL PROTECTED] I'm trying to replace all occurances of the X character in a text with Y, but only those X's that occur between bold tags (b/b). ?php $str = 'This X and this X will not be fixed, but bthis X and/b and hopefully this bX/b should be, along b with this X also. /b, but not this X.'; function myreplace($match) { $from = 'X'; $to = 'Y'; return str_replace($from,$to,$match[0]); } $new_str = preg_replace_callback('#b.*/b#Uis','myreplace',$str); echo $new_str; ? It works great, thank you. I had tried something on my own previously, but without the ungreedy modifier and with replacements inside a repeated while{} cycle instead of a callback. The main drawback in my version was that an X near hopefully would have been replaced as well (since technically it is between b and /b). But that wasn't what I wanted, of course. -- Romanian Web Developers - http://ROWD.ORG -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regular expression help
I'm trying to figure out how to formulate a regular expression that will get me everything following a pound sign (#) up to the first space or { character. (I'm trying to parse the ids out of a style sheet.) Can anyone point me in the right direction? I've been searching on the web for hours and reading everything I can find on regular expressions, but I just can't wrap my brain around it. Thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular expression help
Daniel Lahey wrote: I'm trying to figure out how to formulate a regular expression that will get me everything following a pound sign (#) up to the first space or { character. (I'm trying to parse the ids out of a style sheet.) Can anyone point me in the right direction? I've been searching on the web for hours and reading everything I can find on regular expressions, but I just can't wrap my brain around it. Thanks. preg_match_all('/#([^\s{]+)/',$style_sheet,$matches); $matches[1] should have all of the matches... -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular expression help
On Tue, 24 Aug 2004 23:53:53 -0700, Daniel Lahey [EMAIL PROTECTED] wrote: I'm trying to figure out how to formulate a regular expression that will get me everything following a pound sign (#) up to the first space or { character. (I'm trying to parse the ids out of a style sheet.) Can anyone point me in the right direction? I've been searching on the web for hours and reading everything I can find on regular expressions, but I just can't wrap my brain around it. Thanks. Try this snippet pre ?php $css = fopen(http://www.csszengarden.com//001/001.css;, r); $data = fread($css, 3); preg_match_all(/#.+({ )/, $data, $out); print_r($out); ? /pre It gets the default css from the zengarden site. (30k is a large buffer, but this is not a howto on buffered reads) The regular expression /#.+({ )/ means, piece by piece # the # character . dot is a special character in regular expressions. it can match any character + is also a special character, it means match 1 or more times so .+ means match any character 1 or more times ( ) are special characters, they match any single character inside them. in the case of ({ ) , it matches either a space or a left bracket So, the whole expression means: match a strings where they start with #, followed by 1 or more characters, followed by a space or a left-bracket Note that these are very simplified explanations for regular expressions. Now, try the expression /#(.+)({ )/ and instead of print_r($out), try print_r($out[1]); Now you get the classnames :) Check out the following sites for more info (they appear first when you google regular expressions). http://sitescooper.org/tao_regexps.html http://etext.lib.virginia.edu/helpsheets/regex.html Also, check out the PHP manual for the preg_* functions --- Note that the script i gave you has problems with classnames on one line, like #footer a:link, #footer a:visited But I won't spoon feed you :) ramil http://ramil.sagum.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regular Expression Help
Hi folks. I'm having a little bit of a stupid moment with a regular expression which I'm hoping someone can lend a hand with. The regular expression I have right now matches strings between 2 and 1000 characters in length that start with one of the following characters: a-z A-Z 0-9 ( ) and where the rest of the string may be made up of the following characters: a-z A-Z 0-9 ( ) _ , . - ' Here's the working regular expresssion: /^[a-zA-Z0-9\(\)]{1}[ a-zA-Z0-9\(\)_\,\.\-\'\]{1,999}$/ Now, I'm trying to add \ to the valid characters but when I add a slash after \ I get the following error: Warning: Compilation failed: missing terminating ] for character class at offset 54 in /u0/vservers/*/html/classes/forms/forms_validation_functions.class.p hp on line 184 So I escape the \ with another \, and I still get the error. Three or four \ results in the \ character being stripped from the string that is being tested with the regular expression. Five \ results in the orignal error which I get with just one \. Can anyone give any advice as to why this is happening? Cheers and TIA. Pablo /^[a-zA-Z0-9\(\)]{1}[ a-zA-Z0-9\(\)_\,\.\-\'\]{1,999}$/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regular Expression Help
Howdy folks. Sorry for the message which just showed up truncated. It's complete in my sent mail, but appeared truncated on the list. Full message is below. TIA for all help. Hi folks. I'm having a little bit of a stupid moment with a regular expression which I'm hoping someone can lend a hand with. The regular expression I have right now matches strings between 2 and 1000 characters in length that start with one of the following characters: a-z A-Z 0-9 ( ) and where the rest of the string may be made up of the following characters: a-z A-Z 0-9 ( ) _ , . - ' Here's the working regular expresssion: /^[a-zA-Z0-9\(\)]{1}[ a-zA-Z0-9\(\)_\,\.\-\'\]{1,999}$/ Now, I'm trying to add \ to the valid characters but when I add a slash after \ I get the following error: Warning: Compilation failed: missing terminating ] for character class at offset 54 in /u0/vservers/*/html/classes/forms/forms_validation_functions.class.p hp on line 184 So I escape the \ with another \, and I still get the error. Three or four \ results in the \ character being stripped from the string that is being tested with the regular expression. Five \ results in the orignal error which I get with just one \. Can anyone give any advice as to why this is happening? Cheers and TIA. Pablo -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular Expression Help
* Thus wrote Pablo Gosse: Here's the working regular expresssion: /^[a-zA-Z0-9\(\)]{1}[ a-zA-Z0-9\(\)_\,\.\-\'\]{1,999}$/ for starters, that doesn't give me a warning at all. also, all those escapes arn't needed: $reg = '/^[a-zA-Z0-9()]{1}[ a-zA-Z0-9()_,.\'-]{1,999}$/'; The ' is only escaped for php, not the expression. And moving the - to the end or beginning, you don't need to escape it. Curt -- First, let me assure you that this is not one of those shady pyramid schemes you've been hearing about. No, sir. Our model is the trapezoid! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular Expression Help
I want to extract from a large number of html files everything between the following specified comments, including the comments themselves: !--Begin CMS Content--...!-- End CMS Content-- snip And the regular expression I've got is '/[!--Begin CMS Content\-\-].+[!-- End CMS Content\-\-]/s' I expected that when I ran this using preg_match_all I would get two matches Those brackets mean match one any of the characteres found within, so it will match '', or '!', or '-', or 'B', or... You want this: '/!--Begin CMS Content--(.+)!-- End CMS Content--/Uis' ...which gets you this (I added the parentheses in the middle so you could also get the stuff inside the CMS content delimiters): Array ( [0] = Array ( [0] = !--Begin CMS Content-- span class=headlineBreadth Requirement/span hr class=under / !-- End CMS Content-- [1] = !--Begin CMS Content-- strongMore Matched Content!/strong !-- End CMS Content-- ) [1] = Array ( [0] = span class=headlineBreadth Requirement/span hr class=under / [1] = strongMore Matched Content!/strong ) ) - michal migurski- contact info and pgp key: sf/cahttp://mike.teczno.com/contact.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regular Expression Help
Hi folks. I'm having a little trouble with a regular expression and I'm hoping someone can point out what I'm doing wrong. I want to extract from a large number of html files everything between the following specified comments, including the comments themselves: !--Begin CMS Content--...!-- End CMS Content-- The string I'm testing the expression against is: 'Some code that will be ignored. !--Begin CMS Content-- span class=headlineBreadth Requirement/span hr class=under / !-- End CMS Content-- This is some more content that will not be matched. !--Begin CMS Content-- strongMore Matched Content!/strong !-- End CMS Content-- Some more ignored code.' And the regular expression I've got is '/[!--Begin CMS Content\-\-].+[!-- End CMS Content\-\-]/s' I expected that when I ran this using preg_match_all I would get two matches, the comments and the content between them, but instead I get the following: Array ( [0] = Array ( [0] = Some code that will be ignored. !--Begin CMS Content-- span class=headlineBreadth Requirement/span hr class=under / !-- End CMS Content-- This is some more content that will not be matched. !--Begin CMS Content-- strongMore Matched Content!/strong !-- End CMS Content-- Some more ignored code ) ) which is just a match of the whole string minus the period at the very end which is not matched. Can anybody point out where I'm going wrong here? Cheers and TIA, Pablo. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regular expression help?
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']) so it should match 2 characters 0-9a-fA-F each block of 2 characters is followed by a : and repreated in 6 blocks. Jas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular expression help?
On Mon, 2004-02-02 at 14:15, Jas wrote: 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']) so it should match 2 characters 0-9a-fA-F each block of 2 characters is followed by a : and repreated in 6 blocks. That's a long expression, try: !preg_match('/^([0-9a-f]{2}($|:)){6}/i', $_POST['mac']); This pattern finds 6 matches of a number or letter (the /i means case-insensitive) followed by either a ':' or the end of the string. -- Adam Bregenzer [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular expression help?
Adam Bregenzer wrote: On Mon, 2004-02-02 at 14:15, Jas wrote: 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']) so it should match 2 characters 0-9a-fA-F each block of 2 characters is followed by a : and repreated in 6 blocks. That's a long expression, try: !preg_match('/^([0-9a-f]{2}($|:)){6}/i', $_POST['mac']); This pattern finds 6 matches of a number or letter (the /i means case-insensitive) followed by either a ':' or the end of the string. Thanks, that worked like a charm. Jas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular expression help?
Jas wrote: Adam Bregenzer wrote: On Mon, 2004-02-02 at 14:15, Jas wrote: 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']) so it should match 2 characters 0-9a-fA-F each block of 2 characters is followed by a : and repreated in 6 blocks. That's a long expression, try: !preg_match('/^([0-9a-f]{2}($|:)){6}/i', $_POST['mac']); This pattern finds 6 matches of a number or letter (the /i means case-insensitive) followed by either a ':' or the end of the string. Thanks, that worked like a charm. Jas You may want to check out The Regex Coach. It's very helpful. :-) http://www.weitz.de/regex-coach/ -- paperCrane Justin Patrin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular Expression Help Please
On 27 Nov 2003 at 11:48, Shaun wrote: Hi, I need to generate a lowercase alphanumeric passwrord thats 8 characters long, has anyone got a function that can do this? Thanks for your help -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Umm, I don't know of a function already definedbut it shouldn't be that hard to generate .in pseudocode : 1.Create an array containing the lower case letters as well as the digits 2. Pick a random integer between 0 and 35 (n) 3. Retrieve the character in array[n] 4. Add to password string. 5. Loop through another seven times HTH Rory McKinley Nebula Solutions +27 82 857 2391 [EMAIL PROTECTED] There are 10 kinds of people in this world, those who understand binary and those who don't (Unknown) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular Expression Help: genreate alphanumeric, 8 chars
Adam -- ...and then Adam i Agnieszka Gasiorowski FNORD said... % ... % How about, % % $password = strtolower(substr(md5(uniqid(time())), 0, 7)); Hey, that's pretty slick. Good one! Gonna have to remember that; it's an excellent trick. Thanks HAND :-D -- David T-G * There is too much animal courage in (play) [EMAIL PROTECTED] * society and not sufficient moral courage. (work) [EMAIL PROTECTED] -- Mary Baker Eddy, Science and Health http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg! pgp0.pgp Description: PGP signature
[PHP] Regular Expression Help: genreate alphanumeric, 8 chars
Hi, I need to generate a lowercase alphanumeric passwrord thats 8 characters long, has anyone got a function that can do this? Thanks for your help -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regular Expression Help Please
Hi, I need to generate a lowercase alphanumeric passwrord thats 8 characters long, has anyone got a function that can do this? Thanks for your help -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular Expression Help: genreate alphanumeric, 8 chars
Shaun -- [No need to post twice...] ...and then Shaun said... % % Hi, Hi! % % I need to generate a lowercase alphanumeric passwrord thats 8 characters % long, has anyone got a function that can do this? This isn't really a regular expression question, since you'd use an expression to check if a string matched your requirements but not to generate such a string. A function should be easy: just loop 8 times over spitting out a random char between a and z or 0 and 9 (use rand() to generate a number between 0 and 35 and then map that to the char). % % Thanks for your help Enjoy :-) HTH HAND :-D -- David T-G * There is too much animal courage in (play) [EMAIL PROTECTED] * society and not sufficient moral courage. (work) [EMAIL PROTECTED] -- Mary Baker Eddy, Science and Health http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg! pgp0.pgp Description: PGP signature
Re: [PHP] Regular Expression Help: genreate alphanumeric, 8 chars
...as in... ? // Could've been done with ASCII sets, but this way // you can easily tweak the eligible characters. $eligible='abcdefghijklmnopqrstuvwxyz0123456789'; $pwdLen=8; $password=''; for($i=0;$i$pwdLen;$i++) { $password.=$eligible[rand(0,strlen($eligible))]; } echo(Your new password: $password\n); ? Bogdan David T-G wrote: Shaun -- [No need to post twice...] ...and then Shaun said... % % Hi, Hi! % % I need to generate a lowercase alphanumeric passwrord thats 8 characters % long, has anyone got a function that can do this? This isn't really a regular expression question, since you'd use an expression to check if a string matched your requirements but not to generate such a string. A function should be easy: just loop 8 times over spitting out a random char between a and z or 0 and 9 (use rand() to generate a number between 0 and 35 and then map that to the char). % % Thanks for your help Enjoy :-) HTH HAND :-D -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular Expression Help: genreate alphanumeric, 8 chars
Bogdan -- ...and then Bogdan Stancescu said... % % ...as in... % % ? % // Could've been done with ASCII sets, but this way % // you can easily tweak the eligible characters. % $eligible='abcdefghijklmnopqrstuvwxyz0123456789'; % $pwdLen=8; % $password=''; % for($i=0;$i$pwdLen;$i++) { % $password.=$eligible[rand(0,strlen($eligible))]; % } % echo(Your new password: $password\n); % ? Looks good to me. You're too kind; I was going to leave the exercise to the student to complete :-) % % Bogdan HTH HAND :-D -- David T-G * There is too much animal courage in (play) [EMAIL PROTECTED] * society and not sufficient moral courage. (work) [EMAIL PROTECTED] -- Mary Baker Eddy, Science and Health http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg! pgp0.pgp Description: PGP signature
Re: [PHP] Regular Expression Help: genreate alphanumeric, 8 chars
Shaun wrote: Hi, I need to generate a lowercase alphanumeric passwrord thats 8 characters long, has anyone got a function that can do this? No, but I can write a quick one for you. Can't guarantee the uniqueness of the password being generated. function passgen() { srand((float) microtime() * 1000); //Source arrays $letters = range('a','z'); $digits = range(1,9); //Get random items from arrays $char = array_rand($letters, 4); $num = array_rand($digits, 4); //Combine the two random items into one array for ($i = 0; $i 4; ++$i) { $ran_char[] = $letters[$char[$i]]; $ran_num[] = $digits[$num[$i]]; } //build our password $password = array_unique(array_merge($ran_char, $ran_num)); //randomize it shuffle($password); return join(,$password); } echo passgen(); ? -- Burhan Khalid phplist[at]meidomus[dot]com http://www.meidomus.com --- Documentation is like sex: when it is good, it is very, very good; and when it is bad, it is better than nothing. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular Expression Help: genreate alphanumeric, 8 chars
David T-G wrote: Bogdan -- ...and then Bogdan Stancescu said... % % ...as in... % % ? % // Could've been done with ASCII sets, but this way % // you can easily tweak the eligible characters. % $eligible='abcdefghijklmnopqrstuvwxyz0123456789'; % $pwdLen=8; % $password=''; % for($i=0;$i$pwdLen;$i++) { % $password.=$eligible[rand(0,strlen($eligible))]; % } % echo(Your new password: $password\n); % ? Looks good to me. You're too kind; I was going to leave the exercise to the student to complete :-) How about, $password = strtolower(substr(md5(uniqid(time())), 0, 7)); Will get you a unique password consisting of 8 rather random lowercase alphanumerics. -- Seks, seksi, seksolatki... news:pl.soc.seks.moderowana http://hyperreal.info { iWanToDie } WiNoNa) ( http://szatanowskie-ladacznice.0-700.pl foReVeR( * ) Poznaj jej zwiewne ksztaty... http://www.opera.com 007 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regular expression help
I need someone to tell me exactly what this regular-expression means: if(ereg([^ \t\n],$val)) { // do the job here } I'm looking for an intermittent bug, and I need to understand this to make sure I have found the bug. Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Regular expression help
This condition is true if there is no space, new line or tabulator in $val I need someone to tell me exactly what this regular-expression means: if(ereg([^ \t\n],$val)) { // do the job here } I'm looking for an intermittent bug, and I need to understand this to make sure I have found the bug. Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php S pozdravem Bronislav Klucka =[ pro2-soft.com ]= Bronislav Klucka Pro2-Soft +420 605 582 922 [EMAIL PROTECTED] * Windows Web applications, Computer traininghttp://pro2-soft.com --- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular expression help
Thanks Bronislav for your answer but this can't be it as the following test code passes validation: ?Php $val = \t test \n; if(ereg([^ \t\n],$val)) { echo 'In here!!'; } echo 'BR' . nl2br($val); ? Anyone has an idea? Bronislav kluèka [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] This condition is true if there is no space, new line or tabulator in $val I need someone to tell me exactly what this regular-expression means: if(ereg([^ \t\n],$val)) { // do the job here } I'm looking for an intermittent bug, and I need to understand this to make sure I have found the bug. Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php S pozdravem Bronislav Klucka =[ pro2-soft.com ]= Bronislav Klucka Pro2-Soft +420 605 582 922 [EMAIL PROTECTED] * Windows Web applications, Computer training http://pro2-soft.com -- - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular expression help
Hi, ^ inside [] means not the following chars, so your expression means: if ($val contains no space , no tab \t and no newline \n) { //do the job ... } Regards, Matthias Ben wrote: I need someone to tell me exactly what this regular-expression means: if(ereg([^ \t\n],$val)) { // do the job here } I'm looking for an intermittent bug, and I need to understand this to make sure I have found the bug. Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular expression help
From: Bronislav Kluka [EMAIL PROTECTED] I need someone to tell me exactly what this regular-expression means: if(ereg([^ \t\n],$val)) { // do the job here This condition is true if there is no space, new line or tabulator in $val Actually, the regular expression will match anything that is NOT a space, tab, or newline. That's what the ^ character does (negates the matching). So, if $val has anything that is NOT a space, newline, or tab in it, then the ereg() function will return true. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular expression help
That's it! Thank you very much, you have the answer. I wonder why the programmer did not write the following line instead: if (strlen(trim($val))) { // Do the job here } Anyways, you just proved that I did not fix the bug! Now I have to work even more! :-P Thanks Matthias Nothhaft [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi, ^ inside [] means not the following chars, so your expression means: if ($val contains no space , no tab \t and no newline \n) { //do the job ... } Regards, Matthias Ben wrote: I need someone to tell me exactly what this regular-expression means: if(ereg([^ \t\n],$val)) { // do the job here } I'm looking for an intermittent bug, and I need to understand this to make sure I have found the bug. Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular expression help
* Thus wrote Matthias Nothhaft ([EMAIL PROTECTED]): Hi, ^ inside [] means not the following chars, so your expression means: if ($val contains no space , no tab \t and no newline \n) { //do the job ... } That's not necessarily the correct assesment. rather: if ($val has any character but ' ', '\t', or '\n') { // do the job. } with: test\t\n because 'test' is in there it results a a true statement. Curt -- My PHP key is worn out PHP List stats since 1997: http://zirzow.dyndns.org/html/mlists/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] REGULAR EXPRESSION HELP
-Original Message- From: John [mailto:[EMAIL PROTECTED] Sent: 12 July 2003 07:31 I need to match a pattern, not in a single-line but from a HTML page, which obviously has loads of lines. I need to match 2 lines from this HTML page: 1) HTMLTITLEFirstVariable - Second Variable/TITLE/HTML 2) TABLETDTR(newline) ThirdVariable/TR/TD/TABLE... I tried this code: 1) preg_match(/HTMLTITLE(\S+) - (\S+)/TITLE/HTML/, $html_page, $variables); 2) preg_match(/TABLETDTR\n(\S+)/TR/TD/TABLE/, $html_page, $variables); The first 2 variables are matched into the $variables array but not the third one. Sometimes when the third one is matched, it starts from where I want it to start but takes all the text to the end of the HTML document! Any ideas? Is there any characters that I should have escaped that I didn't?? All I can think of is that because the first line that I want to match is on the FIRST LINE of the html page, that matches. But reg-ex can't handle the next line as its way down the page Firstly, your newsline may actually be any of \n, \r, or \r\n according as the file was built on a *nix, Mac or PC platform, so your regex should take account of this. Secondly, both of your examples should produce scads of errors attempting to parse the regular expression, because you have unescaped slashes and your delimiters are also slashes -- so either this is not a direct cut-and-paste of what's actually in your script, or you're not letting on about something else! The fix for this one is either to escape the slashes that are actually part of the match, or use something other than / as your delimiter. Thirdly, as you've got double quotes around the regex, it would be advisable to double the backslashes themselves (to ensure PHP doesn't attempt to interpret any of its own backslash sequences) -- either that or use single quotes to enclose the regex. Fourthly, and perhaps most importantly, by default the * and + modifiers are greedy -- that is, they match as much as possible consistent with the whole match succeeding. With your first match, this doesn't matter as there's only one /TITLE in the document, so there's no ambiguity; with the second match, there could be any number of occurrences of /TR/TD/TITLE in the document, and the greedy matching of \S+ means that it will always be the *last* of these that is found. The way to counter this is to use one of the ungreedy modifiers in your regex. Taking all of these into account, you probably want something like: preg_match('!TABLETDTR(\n|\r\n|\r)(\S+)/TR/TD/TABLE!U', $html_page, $variables); Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] REGULAR EXPRESSION HELP
John wrote: I need to match a pattern, not in a single-line but from a HTML page, which obviously has loads of lines. I need to match 2 lines from this HTML page: 1) HTMLTITLEFirstVariable - Second Variable/TITLE/HTML 2) TABLETDTR(newline) ThirdVariable/TR/TD/TABLE... I tried this code: 1) preg_match(/HTMLTITLE(\S+) - (\S+)/TITLE/HTML/, $html_page, $variables); 2) preg_match(/TABLETDTR\n(\S+)/TR/TD/TABLE/, $html_page, $variables); The first 2 variables are matched into the $variables array but not the third one. Sometimes when the third one is matched, it starts from where I want it to start but takes all the text to the end of the HTML document! Your newline may be \r\n or \r instead of just \n. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ PHP|Architect: A magazine for PHP Professionals www.phparch.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] REGULAR EXPRESSION HELP
Hi, I'm pretty new to regular expressions. Before, I used to write long-winded and buggy segments of code with PHPs string functions to extract text. But I want to learn how to use perl reg-ex as it seems useful to know so I ordered Mastering Regular Expressions. But it hasn't come yet so I'm asking for help... I need to match a pattern, not in a single-line but from a HTML page, which obviously has loads of lines. I need to match 2 lines from this HTML page: 1) HTMLTITLEFirstVariable - Second Variable/TITLE/HTML 2) TABLETDTR(newline) ThirdVariable/TR/TD/TABLE... I tried this code: 1) preg_match(/HTMLTITLE(\S+) - (\S+)/TITLE/HTML/, $html_page, $variables); 2) preg_match(/TABLETDTR\n(\S+)/TR/TD/TABLE/, $html_page, $variables); The first 2 variables are matched into the $variables array but not the third one. Sometimes when the third one is matched, it starts from where I want it to start but takes all the text to the end of the HTML document! Any ideas? Is there any characters that I should have escaped that I didn't?? All I can think of is that because the first line that I want to match is on the FIRST LINE of the html page, that matches. But reg-ex can't handle the next line as its way down the page TIA -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regular Expression Help in my PHP! Sorry if wrong group
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
Re: [PHP] Regular Expression Help in my PHP! Sorry if wrong group
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. Well, a /U at the end of your pattern will make it so the regex isn't greedy. That may solve your problem. Or you could try matching /a[^]+(Tampa)\/a/ which will match an a followed by anything that's not a , followed by a . So it essentially makes it ungreedy. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regular Expression Help in my PHP! Sorry if wrong group
Thanks for the response. I found this web page (http://www.itworld.com/nl/perl/01112001/) right after I submitted my question. It was great for explaining regexp's greediness. 1lt John W. Holmes 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. Well, a /U at the end of your pattern will make it so the regex isn't greedy. That may solve your problem. Or you could try matching /a[^]+(Tampa)\/a/ which will match an a followed by anything that's not a , followed by a . So it essentially makes it ungreedy. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] regular expression help
I'm a bit useless at regular expressions so i thought i ask. i need to turn all [link url=http://www.site.com] link to site [/link] in a string into html a href= ...etc and back again. thanks adrian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regular expression help
Here is your answer: http://www.phpbuilder.com/columns/ying2718.php3?page=2 -- Maxim Maletsky [EMAIL PROTECTED] adrian [EMAIL PROTECTED] [EMAIL PROTECTED] wrote... : I'm a bit useless at regular expressions so i thought i ask. i need to turn all [link url=http://www.site.com] link to site [/link] in a string into html a href= ...etc and back again. thanks adrian -- 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
Re: [PHP] regular expression help
why don't you just use str_replace ? I'm a bit useless at regular expressions so i thought i ask. i need to turn all [link url=http://www.site.com] link to site [/link] in a string into html a href= ...etc and back again. thanks adrian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php _ Help STOP SPAM: Try the new MSN 8 and get 2 months FREE* http://join.msn.com/?page=features/junkmail -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Regular expression help converting doc to xml
(For the archives) The RegEx I finally used was this: search: D(.*) replace: DD\1/DD I tried this in 3 editors: jEdit, eMacs and BBEdit jEdit interpreted the replace expression as literally \1 eMacs didn't like the parenthesis in the search string In BBEdit it worked like a charm. Not sure why. Perhaps different implementations of RegEx. Is this true? On Fri, 2002-09-27 at 16:53, John Holmes wrote: I have a fairly large html document that I need to convert to xml. The current format is is: DD A whole bunch of text DT Something else /DT (There is a new line in there before DT) Which I need to convert to DD A whole bunch of text /DD DT Something else /DT $new_text = str_replace(\n\tDT,/DD\n\tDT,$your_text); Assuming there is a tab in there... You'd be better off getting an editor that'll do this for you. Textpad lets you search and replace with regular expressions. Other programs do too. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Regular expression help converting doc to xml (somewhatOT)
On Fri, 2002-09-27 at 16:53, John Holmes wrote: This isn't accurate enough because DT is not always preceeded by: DD some text. It is sometimes preceeded by DT some text /DT or other items. This expression matches fairly well: DD[a-zA-Z0-9\.,'\-\s]* So it matches up to the DT: DD A whole bunch of text DT Something else /DT But I don't know how to do the replace part. So essentially I need find this: DD A whole bunch of text and replace it with this: DD A whole bunch of text /DD $new_text = str_replace(\n\tDT,/DD\n\tDT,$your_text); Assuming there is a tab in there... You'd be better off getting an editor that'll do this for you. Textpad lets you search and replace with regular expressions. Other programs do too. ---John Holmes... I have a fairly large html document that I need to convert to xml. The current format is is: DD A whole bunch of text DT Something else /DT (There is a new line in there before DT) Which I need to convert to DD A whole bunch of text /DD DT Something else /DT -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regular expression help converting doc to xml
I have a fairly large html document that I need to convert to xml. The current format is is: DD A whole bunch of text DT Something else /DT (There is a new line in there before DT) Which I need to convert to DD A whole bunch of text /DD DT Something else /DT Any ideas?? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Regular expression help converting doc to xml
I have a fairly large html document that I need to convert to xml. The current format is is: DD A whole bunch of text DT Something else /DT (There is a new line in there before DT) Which I need to convert to DD A whole bunch of text /DD DT Something else /DT $new_text = str_replace(\n\tDT,/DD\n\tDT,$your_text); Assuming there is a tab in there... You'd be better off getting an editor that'll do this for you. Textpad lets you search and replace with regular expressions. Other programs do too. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regular Expression Help
Hello everyone, I'm using regular expression to extract all text within the body tag. With a BODY tag like body bgcolor= ... text= \\only interested in this line. I use eregi(( body ) (.*) (\) ,$str,$out); \\spaces included, here, for easy reading. echo $out[0]; However, this prints everything following (and including) the 'BODY' portion of the BODY tag. Ex. body text= ...alink= table/table ... /body /html I want it to ONLY take the text within the openning body tag. Like, body ... how do I do this? What am I missing, in the above? eregi((body)(.*)(),$str,$out); -Please help. -john -- 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] Regular Expression Help
* John Monfort ([EMAIL PROTECTED]) [Dec 31. 2001 11:30]: I'm using regular expression to extract all text within the body tag. With a BODY tag like body bgcolor= ... text= \\only interested in this line. [...] echo $out[0]; However, this prints everything following (and including) the 'BODY' portion of the BODY tag. $matches[0] will contain the text that matched the full pattern, $matches[1] will have the text that matched the first captured parenthesized subpattern So you want: $out[1] -- Brian Clark | Avoiding the general public since 1805! Fingerprint: 07CE FA37 8DF6 A109 8119 076B B5A2 E5FB E4D0 C7C8 Press Ctrl-Alt-Del for more information. -- 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] regular expression help
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] Regular Expression help
try something like this: $emails = array('[EMAIL PROTECTED]', '[EMAIL PROTECTED]', '[EMAIL PROTECTED]', '[EMAIL PROTECTED]'); $doms = array( 'domain1.com'=1, 'domain2.com'=1, ); while ( list(,$email) = each($emails) ) { preg_match('/^([_\.0-9a-z-]+)@(([0-9a-z][0-9a-z-]+)+\.[a-z]{2,3})$/', $email, $matches); if ($doms[ $matches[2] ]) { print $email Good!\n; } else { print $email Bad!\n; } } -Original Message- From: Clayton Dukes [mailto:[EMAIL PROTECTED]] Sent: Friday, June 29, 2001 9:43 AM To: Clayton Dukes; [EMAIL PROTECTED] Subject: [PHP] Re: Regular Expression help 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] -- 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] 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]
[PHP] Regular Expression Help
I'm trying to figure out how to say with a Regular Expression how to check for the following characters in a phone number: ( ) - with a length between 1 and 20 -- I've tried the following and it doesn't seem to work. eregi(^([0-9]|\\(|\\)|\\-){1,20}$) I'm not interested in checking for a completely valid phone number... but instead checking to see if the phone number is numbers with or without the ( ) - characters. Plus, I think creating a Regex expr that can check for US and International formats would be too complex. Thanks. Jason -- 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] Regular Expression Help
On Tue, 22 May 2001 10:44:42 -0700, Jason Caldwell ([EMAIL PROTECTED]) wrote: I'm trying to figure out how to say with a Regular Expression how to check for the following characters in a phone number: ( ) - with a length between 1 and 20 -- I've tried the following and it doesn't seem to work. eregi(^([0-9]|\\(|\\)|\\-){1,20}$) oops, make that: ^[0-9\\(\\)-]{1,20}$ note: you don't have to escape the - when its the last char in the range I'm not interested in checking for a completely valid phone number... but instead checking to see if the phone number is numbers with or without the ( ) - characters. Plus, I think creating a Regex expr that can check for US and International formats would be too complex. Thanks. Jason -- 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: php-list- [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] Regular Expression Help
On Tuesday 22 May 2001 19:44, Jason Caldwell wrote: I'm trying to figure out how to say with a Regular Expression how to check for the following characters in a phone number: ( ) - with a length between 1 and 20 -- preg_match ('/^[\d()-]{1,20}$/', $Subject) should do the trick. -- Christian Reiniger LGDC Webmaster (http://sunsite.dk/lgdc/) Nothing is more dangerous than an idea if it's the only one you have. - Emil-Auguste Chartier, Propos sur la religion, 1938 -- 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] Regular Expression Help
I want to delete everything after a tab (or space) on each line of a text file and can't figure it out. An example line is ARIA5.19-0.0625 -1.19 5.254.5 48.5100300 I want to the output to be ARIA Thanks. Jeff Oien -- 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] Regular Expression Help
I want to delete everything after a tab (or space) on each line of a text file and can't figure it out. An example line is ARIA 5.19 -0.0625 -1.19 5.25 4.5 48.5 100300 you can explode on a tab $arrlines = explode("\t", $the_line); then save $arrlines[0] from every line. Don't know if it's the most optimal way but it works :) -- Henrik Hansen -- 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] regular expression help
In article 005801c08668$e0459070$0201010a@shaggy, "Jamie Burns" [EMAIL PROTECTED] wrote: I tried something like this and your examples worked: $str = "tag element = \"value\" nextelement"; if (eregi("=[[:space:]]*\"([^\"]+)|=[[:space:]]*([[:alnum:]]+)",$str,$regs)) { print("yes - ".$regs[1].":".$regs[2]."br\n"); } since the pattern has an 'or' (|), you have to look in either the second or the third element of the array you use to store values from the ereg. Jeff can anyone help me figure out a regular expression to find the value of a tag element? for example: tag element="my value" tag element=value tag element="my value" nextelement tag element=value nextelement tag element = "my value" tag element = value tag element = "my value" nextelement tag element = value nextelement so in each of the above i need to find either "my value" or "value"... i tried this but it wont work for every situation: ereg("element[ ]*[=][ ]*[\"]?([^\"]*)[ |\"|].*" ... thanks for your help - regular expressions are not my best area! jamie. -- 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] regular expression help
can anyone help me figure out a regular expression to find the value of a tag element? for example: tag element="my value" tag element=value tag element="my value" nextelement tag element=value nextelement tag element = "my value" tag element = value tag element = "my value" nextelement tag element = value nextelement so in each of the above i need to find either "my value" or "value"... i tried this but it wont work for every situation: ereg("element[ ]*[=][ ]*[\"]?([^\"]*)[ |\"|].*" ... thanks for your help - regular expressions are not my best area! jamie.