tr8er8

msg:3962847 | 12:48 am on Jul 31, 2009 (gmt 0) |
just make the "John Doe was born on..." a variable: $john = "John Doe was born on..."; and call the variable $john as your subject.
|
ianevans

msg:3962853 | 1:00 am on Jul 31, 2009 (gmt 0) |
I'm sorry, but I think you missed my point. I'm looking for a regular expression (regex) pattern that will find instances of a search text in a string as long as that search text is not contained within <>.
|
coopster

msg:3965592 | 7:18 pm on Aug 4, 2009 (gmt 0) |
You could always strip_tags [php.net] first.
|
rainborick

msg:3965614 | 8:03 pm on Aug 4, 2009 (gmt 0) |
If the goal is to end up with an updated HTML page, I'd be a bit more brute-force in my approach because I believe that strip_tags just leaves you with the page content and no simple way to restore the stripped tags once you've made your changes. I'd start by extracting the content between the <body> tags, followed by replacing all HTML tags with sequentially-numbered markers, storing the tags along the way so they could be restored by replacing the markers. (You might have to special-case <style></style> and <script></script> sections to avoid altering them.) That would make global changes to the document content via regexp simple(r). And once that's done, you just restore the tags that you removed in the first pass, and re-insert the results back into the <body></body>.
|
ianevans

msg:3965639 | 8:34 pm on Aug 4, 2009 (gmt 0) |
Thanks for the tips. Someone at another site suggested this: $str = preg_replace('/John Doe(?![^<>]*+>)/i', $new_name, $str); It seems to work. [edited by: eelixduppy at 3:09 am (utc) on Aug. 5, 2009] [edit reason] disabled smileys [/edit]
|
|