Msg#: 3562722 posted 9:12 pm on Jan 31, 2008 (gmt 0)
'%(?:<[\w\s"']+>)([^<]+)(?:</[\w]+>)%is'; Should work for you as the (?: will stop the start and end tags from getting captured into sub-patterns. So hopefully only the contents of the div in your example will be captured.
The above is for preg not ereg, so if you are using eregi then you can get rid of the i just after the final %.
The first set of ()'s will capture a < with any number of letters, _ or space characters followed by another >. So this should match a start tag. The [^<]+ will match any number of characters that are not a <. So this should match anything other than a end tag as this will start with <. The final part will match an end tag.
You may well need to adjust this if you are going to be using this on tags with other tags inside them. However the pattern should get you started.
[edited by: eelixduppy at 11:02 pm (utc) on Jan. 31, 2008] [edit reason] disabled smileys [/edit]
Msg#: 3562722 posted 6:36 pm on Feb 12, 2008 (gmt 0)
You are going to have to make the replacement with what was already found in the string. So you have to change your pattern and your replacement string to do just that. Try the following: $pattern = "/(?!<.*?)(".preg_quote($key,'/').")(?![^<>]*?>)/si"; $replacement = "<b>\\2</b>"; $pagecontent = preg_replace($pattern,$replacement,$pagecontent);