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.html">aaa</a>
> >>
> >> <a href="bbb.html">cfdfd</a>
> >>
> >> <a href="aaa.html">sfs
> >> sfsrbbb
> >> sfds</a>
> >>
> >> <a href="aaa.html">cc
> >> gd
> >> c</a>
> >>
> >> <a href="aaa.html">ddd
> >> 123</a>
> >> eof;
> >>
> >> /*
> >> i want replace any |<a.has bbb.</a>|, like
> >> <a href="bbb.html">cfdfd</a>
> >>
> >> <a href="aaa.html">sfs
> >> 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