haaglin Posted June 24, 2007 Share Posted June 24, 2007 Hi. I have this expression to find any emails in a document: $reg = '([[:alnum:]_\.\-]+)(\@[[:alnum:]\.\-]+\.+)([[:alnum:]\.\-]+)'; while( eregi($reg, $content, $regs ) ) { //do some stuff with te found address in $content. } This works fine, but i want it to find all emails except those inside input tags (and only input tags) , like this one: <input type="text" value="name@domain.com"/> How do i do that? Quote Link to comment Share on other sites More sharing options...
effigy Posted June 25, 2007 Share Posted June 25, 2007 You can do so with this method, or change your expression to PCRE and use lookarounds, e.g., (?<!="). Quote Link to comment Share on other sites More sharing options...
haaglin Posted June 26, 2007 Author Share Posted June 26, 2007 How do i convert it to PCRE? I tried this, and it didn't work.. $reg = '/(?<!=")([[:alnum:]_\.\-]+)(\@[[:alnum:]\.\-]+\.+)([[:alnum:]\.\-]+)/'; while( eregi($reg, $content, $regs ) ) { //do some stuff with te found address in $content. } Quote Link to comment Share on other sites More sharing options...
haaglin Posted June 26, 2007 Author Share Posted June 26, 2007 Almost got it i think, but it still returns the emails, except for the first letter. $reg = '/(?<!=")(([[:alnum:]_\.\-]+)(\@[[:alnum:]\.\-]+\.+)([[:alnum:]\.\-]+))/'; while( preg_match($reg, $content, $regs ) ) { //do some stuff with te found address in $content. } Quote Link to comment Share on other sites More sharing options...
haaglin Posted June 26, 2007 Author Share Posted June 26, 2007 Solved it. This it what i did: $reg = '/([[:alnum:]_\.\-]+)(\@[[:alnum:]\.\-]+\.+)([[:alnum:]\.\-]+)/'; preg_match ($reg, $content, $regs ); $mail = $regs[0]; while( preg_match ("/(?<!value=\")$mail/", $content, $regs ) ) { $content = preg_replace("/(?<!value=\")$mail/", $replace, $content ); preg_match ($reg, $content, $regs ); $mail = $regs[0]; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.