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

----- Original Message ----- 
From: "Jim" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, December 19, 2002 11:55 AM
Subject: Re: [PHP] Regex Help


I'm sorry, I accidentally left the slashes on my second example. My original
message should read:

Could someone show me how to use preg_replace to change this:

test <OPTION VALUE="test">test</OPTION> test

into:

anotherword <OPTION VALUE="test">test</OPTION> anotherword

Note that what I want to accomplish is to change 'test' into 'anotherword'
only if it is not within the option tag.

Thanks!


----- Original Message -----
From: "Rick Emery" <[EMAIL PROTECTED]>
To: "Jim" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Thursday, December 19, 2002 12:42 PM
Subject: Re: [PHP] Regex Help


> addslashes()
>
> ----- Original Message -----
> From: "Jim" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Thursday, December 19, 2002 11:26 AM
> Subject: [PHP] Regex Help
>
>
> Could someone show me how to use preg_replace to change this:
>
> test <OPTION VALUE="test">test</OPTION> test
>
> into:
>
> anotherword <OPTION VALUE=\"test\">test</OPTION> anotherword
>
> basically, I want to change a value only if it is not in an option
> tag.....
>
> I also want to account for situations like :
>
> test, something <OPTION VALUE="test">test</OPTION> test!
>
> My thoughts were to do the replace if the word (test) was not
> surrounded by quotes or surrounded by greater/less than symbols. I
> just have no idea how to formulate that with regex.
>
> Please help! Thanks.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
>


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




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

Reply via email to