Re: Regex Help
| From: | Rick Emery | Date: | Thu, 19 Dec 2002 18:09:06 +0000 |
| Subject: | Re: Regex Help | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-128891@lists.php.net to get a copy of this message | ||
<?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" <user@lifeforjesus.org>
To: <php-general@lists.php.net>
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" <remery@emeryloftus.com>
To: "Jim" <user@lifeforjesus.org>; <php-general@lists.php.net>
Sent: Thursday, December 19, 2002 12:42 PM
Subject: Re: [PHP] Regex Help
> addslashes()
>
> ----- Original Message -----
> From: "Jim" <user@lifeforjesus.org>
> To: <php-general@lists.php.net>
> 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