Re: [PHP] urgent !!! Please Help preg_replace !!!!!!!!!!!!!!!!!!!!!
this i know already, but i think can do it single regex Robert Cummings [EMAIL PROTECTED] ¼¶¼g©ó¶l¥ó·s»D:[EMAIL PROTECTED] On Sun, 2008-02-10 at 14:33 +0800, LKSunny wrote: //please run this script, you can get what problem i got $html = eof a href=aaa.htmlaaa/a a href=bbb.htmlcfdfd/a a href=aaa.htmlsfs sfsrbbb sfds/a a href=aaa.htmlcc gd c/a a href=aaa.htmlddd 123/a eof; /* i want replace any |a.has bbb./a|, like a href=bbb.htmlcfdfd/a a href=aaa.htmlsfs sfsrbbb sfds/a */ ?php $reps = array ( array ( 'match' = '#a.*/a#Uims', 'check' = '#bbb#', 'replace' = 'X', ), ); foreach( $reps as $criteria ) { if( preg_match_all( $criteria['match'], $html, $matches ) ) { foreach( $matches[0] as $match ) { if( preg_match( $criteria['check'], $match ) ) { $html = str_replace( $match, $criteria['replace'], $html ); } } } } ? This does what you want to $html, but it doesn't do it in a single regex. I'm not sure it can be done with a single regex, and if it can, I doubt it's simple. I don't feel like investigating too far :) Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] urgent !!! Please Help preg_replace !!!!!!!!!!!!!!!!!!!!!
On Sun, 2008-02-10 at 16:46 +0800, LKSunny wrote: this i know already, but i think can do it single regex Considering you marked the email as urgent, perhaps you have better things to do than try to squeeze your problem into a regex. Feel free to post your single regex when you find it... a side note of how much time you wasted would be most informative too. Cheers, Rob. Robert Cummings [EMAIL PROTECTED] glsD:[EMAIL PROTECTED] On Sun, 2008-02-10 at 14:33 +0800, LKSunny wrote: //please run this script, you can get what problem i got $html = eof a href=aaa.htmlaaa/a a href=bbb.htmlcfdfd/a a href=aaa.htmlsfs sfsrbbb sfds/a a href=aaa.htmlcc gd c/a a href=aaa.htmlddd 123/a eof; /* i want replace any |a.has bbb./a|, like a href=bbb.htmlcfdfd/a a href=aaa.htmlsfs sfsrbbb sfds/a */ ?php $reps = array ( array ( 'match' = '#a.*/a#Uims', 'check' = '#bbb#', 'replace' = 'X', ), ); foreach( $reps as $criteria ) { if( preg_match_all( $criteria['match'], $html, $matches ) ) { foreach( $matches[0] as $match ) { if( preg_match( $criteria['check'], $match ) ) { $html = str_replace( $match, $criteria['replace'], $html ); } } } } ? This does what you want to $html, but it doesn't do it in a single regex. I'm not sure it can be done with a single regex, and if it can, I doubt it's simple. I don't feel like investigating too far :) Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] urgent !!! Please Help preg_replace !!!!!!!!!!!!!!!!!!!!!
At 12:38 PM -0500 2/10/08, Robert Cummings wrote: On Sun, 2008-02-10 at 16:46 +0800, LKSunny wrote: this i know already, but i think can do it single regex Considering you marked the email as urgent, perhaps you have better things to do than try to squeeze your problem into a regex. Feel free to post your single regex when you find it... a side note of how much time you wasted would be most informative too. Cheers, Rob. Rob: It's exchanges like this that piss me off. The OP marked his post as urgent meaning that he needed an answer immediately. You in turn, provide him elegant code that solves his problem, and he replies this i know already. If the OP knew this already, then it wasn't urgent! He certainly could have said Here's my code -- can anyone reduce it to a single regex? But no, he takes advantage of our time by stating a falsehood. I for one, won't be answering any of LKSunny's post. Where do we get people like this? Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] urgent !!! Please Help preg_replace !!!!!!!!!!!!!!!!!!!!!
On Sun, 2008-02-10 at 12:55 -0500, tedd wrote: At 12:38 PM -0500 2/10/08, Robert Cummings wrote: On Sun, 2008-02-10 at 16:46 +0800, LKSunny wrote: this i know already, but i think can do it single regex Considering you marked the email as urgent, perhaps you have better things to do than try to squeeze your problem into a regex. Feel free to post your single regex when you find it... a side note of how much time you wasted would be most informative too. Cheers, Rob. Rob: It's exchanges like this that piss me off. The OP marked his post as urgent meaning that he needed an answer immediately. You in turn, provide him elegant code that solves his problem, and he replies this i know already. If the OP knew this already, then it wasn't urgent! He certainly could have said Here's my code -- can anyone reduce it to a single regex? But no, he takes advantage of our time by stating a falsehood. I for one, won't be answering any of LKSunny's post. Where do we get people like this? There's a colony of them living under the really big rock at the end of the yard :| Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] urgent !!! Please Help preg_replace !!!!!!!!!!!!!!!!!!!!!
On Feb 10, 2008 12:55 PM, tedd [EMAIL PROTECTED] wrote: Where do we get people like this? the late-night homework challenge? -nathan
Re: [PHP] urgent !!! Please Help preg_replace !!!!!!!!!!!!!!!!!!!!!
Rob, $reps = array ( array ( 'match' = '#a.*/a#Uims', Can you explain what the 'U' from #Uims does? Does it have to do with Unicode? I can't find it anywhere (preg_match doc, man perlre, man perlop). Thanks! Michael -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] urgent !!! Please Help preg_replace !!!!!!!!!!!!!!!!!!!!!
On Mon, 2008-02-11 at 13:42 +0900, Michael Moyle wrote: Rob, $reps = array ( array ( 'match' = '#a.*/a#Uims', Can you explain what the 'U' from #Uims does? Does it have to do with Unicode? I can't find it anywhere (preg_match doc, man perlre, man perlop). It makes the match Ungreedy. Look at the following example: $text = a href=blah/a ... a href=bleh/a; If we match with the following: preg_match_all( '#a.*/a#Uims', $html, $matches ) Then $matches will contain 2 matches... 1. a href=blah/a 2. a href=bleh/a However if we match with the following: preg_match_all( '#a.*/a#ims', $html, $matches ) Then $matches will only get 1 match... 1. a href=blah/a ... a href=bleh/a This is because the default behaviour is greedy, it will match as much as possible even if a shorter match exists. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] urgent !!! Please Help preg_replace !!!!!!!!!!!!!!!!!!!!!
On Sun, 2008-02-10 at 14:33 +0800, LKSunny wrote: //please run this script, you can get what problem i got $html = eof a href=aaa.htmlaaa/a a href=bbb.htmlcfdfd/a a href=aaa.htmlsfs sfsrbbb sfds/a a href=aaa.htmlcc gd c/a a href=aaa.htmlddd 123/a eof; /* i want replace any |a.has bbb./a|, like a href=bbb.htmlcfdfd/a a href=aaa.htmlsfs sfsrbbb sfds/a */ ?php $reps = array ( array ( 'match' = '#a.*/a#Uims', 'check' = '#bbb#', 'replace' = 'X', ), ); foreach( $reps as $criteria ) { if( preg_match_all( $criteria['match'], $html, $matches ) ) { foreach( $matches[0] as $match ) { if( preg_match( $criteria['check'], $match ) ) { $html = str_replace( $match, $criteria['replace'], $html ); } } } } ? This does what you want to $html, but it doesn't do it in a single regex. I'm not sure it can be done with a single regex, and if it can, I doubt it's simple. I don't feel like investigating too far :) Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php