There may be better ways, but this little example works. You basically
match everything around the <option> tag and run a replace on what's
outside of it, and then put it all back together. This example should
run as is. Adapt to your needs.
<?
header("Content-type: text/plain");
$word = "test";
$repl = "anotherword";
$new_string = "";
$string =
"This test is a test okay? <option value='test'>test</option> and this
test is good
This test on line 2<option value='whatever'>thing</option>
<option value='foo'>foo</option> test on line 3
<option value='foo2'>foo2</option>
Test<option>test</option>Test";
preg_match_all("/(.*)(<option.*option>)(.*)/i",$string,$match);
$cnt = count($match[1]);
for($x=0;$x<$cnt;$x++)
{
$p1 = preg_replace("/$word/i",$repl,$match[1][$x]);
$p2 = preg_replace("/$word/i",$repl,$match[3][$x]);
$new_string .= $p1 . $match[2][$x] . $p2 . "\n";
}
echo "$string\n--\n$new_string";
?>
---John W. Holmes...
PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/
> -----Original Message-----
> From: Jim [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, December 19, 2002 1:24 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP] Regex Help
>
> Thanks for helping. Unfortunately, that doesn't quite accomplish the
task
> either. The other example for my first post would be mangled with
that.
>
> ----- Original Message -----
> From: "Rick Emery" <[EMAIL PROTECTED]>
> To: "Jim" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
> Sent: Thursday, December 19, 2002 1:09 PM
> Subject: Re: [PHP] Regex Help
>
>
> > <?php
> > $q = "test <OPTION VALUE=\"test\">test</OPTION> test";
> > ereg("(.*)(<OPTION.*OPTION>)(.*)",$q,$ar);
> > $t = "anotherword".$ar[2]."anotherword";
> > print $t;
> > ?>
> >
> > outputs:
> > anotherword<OPTION VALUE="test">test</OPTION>anotherword
> >
>
>
> --
> 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