Google Answers Logo
View Question
 
Q: PHP : using EREGI_REPLACE so that it doesn't search/replace inside HTML tags ( No Answer,   1 Comment )
Question  
Subject: PHP : using EREGI_REPLACE so that it doesn't search/replace inside HTML tags
Category: Computers > Programming
Asked by: dfdfdfdfdfdf-ga
List Price: $6.00
Posted: 31 Jan 2005 10:29 PST
Expires: 02 Mar 2005 10:29 PST
Question ID: 466434
I'm writing some PHP code and I'd like to perform a smart text
replacement using EREGI_REPLACE.
In detail : I'd like to search for a particular string in a larger
string containing plain text mixed with some HTML tags. The difficulty
is : I don't want this search/replacement function to search inside
HTML tags, but ONLY in the rest of the text.

For example, here's some text I want to search into :
----
Hello <A HREF="http://www.something.com">everybody and everything</A>,
how are you ?
----
I'd like to use EREGI_REPLACE so that it replaces the "thing" portion
from "everything" but NOT from the URL inside the <A ...> tag.
How do you do that ?

Clarification of Question by dfdfdfdfdfdf-ga on 31 Jan 2005 12:24 PST
Of course, the answer should apply to ANY HTML tag, not only the <A> tag.
Answer  
There is no answer at this time.

Comments  
Subject: Re: PHP : using EREGI_REPLACE so that it doesn't search/replace inside HTML tags
From: tyronx-ga on 27 Feb 2005 15:33 PST
 
You could use the PREG_OFFSET_CAPTURE flag of the more powerful regexp
function preg_match function and check wether the match is inside a
HTML Tag.
I tried to do the same and ended up with a loop which steps through every character.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy