Re: [PHP] Trying to craft a regexp

From: Burhan Khalid (phplist_at_meidomus.com)
Date: 10/31/03


Date: Fri, 31 Oct 2003 14:51:23 +0300
To: Manuel Vázquez Acosta <manu@chasqui.cu>,  php-general@lists.php.net

Manuel Vázquez Acosta wrote:
> Hi all:
>
> I'm trying to find every simple mail address in an HTML that is not inside
> an A tag.
>
> I have tried this regexp:
> (?<!maito\:)(\w+@\w+(?:\.\w+)+)(?![^<]*?</a>)

Try this (a little more comprehensive) :

preg_match_all("|<a(.*?)href=[\"'](.*?)[\"'](.*?)>(.*?)</a>|i",
$rawHTML, $arrayoflinks);
$links = array_unique($arrayoflinks[0]);
$href = array_unique($arrayoflinks[2]); //href=
$text = array_unique($arrayoflinks[4]); //link text

$text, $href, etc. are arrays. You can print_r() to find out what they
contain.

-- 
Burhan Khalid
phplist[at]meidomus[dot]com
http://www.meidomus.com


Relevant Pages

  • Re: [PHP] Trying to craft a regexp
    ... HTML but all the mail addresses that are not already inside a tag A. ... > Manuel Vázquez Acosta wrote: ... > Burhan Khalid ...
    (php.general)
  • Re: ruby html (or xhtml) forms class...
    ... xx is a library designed to extend ruby objects with html, xhtml, and xml ... xml or xhtml as clean looking and natural as ruby it self. ... attributes may be passed to any tag method as either symbol or string. ...
    (comp.lang.ruby)
  • Re: CSS Safari Problem (Mac)
    ... indirectly quoted, ... anything to say on my point: mixing HTML 4.01 and XHTML 1.0 is clueless. ... The closed meta tag was copied and pasted from Google's Webmaster ... But since this is Usenet, many likely are aware that the theme song ...
    (alt.html)
  • Re: Dynamically assigning functions with parameters to events
    ... which in turn does the work at mouseover-time: ... `onmouseover' is an attribute of the `body' element in Valid HTML ... its start tag. ... That it works in a handful of ...
    (comp.lang.javascript)
  • wierd behavior in program
    ... I am reading a file with html tags in ... I read each tag and push it on the stack and pop it when I ... int degree; ...
    (comp.lang.c)