Jump to content

eeart

New Members
  • Posts

    3
  • Joined

  • Last visited

Everything posted by eeart

  1. That HTML Dom Parser is brilliant! Thank you so much, johnny86. This does exactly what I need!
  2. Thank you sasa, but I don't want to remove all existing classes and I only want to add the new class to hyperlinks with a specific URL. The purpose is to mark hyperlinks with a broken or bad URL. So for example a text may have 20 hyperlinks and I only want to add a class "broken_link" to all hyperlinks with URL http://www.badlink.com
  3. I have 2 regex questions related to hyperlinks: 1. I am trying to add a class to hyperlinks with a certain URL. What I have now is this: $pattern = "/<a href=[\'\"](" . $url . ")[\'\"]>(.*)<\/a>/is"; $replace = "<a href=\"$1\" class=\"". $class_name ."\">$2</a>"; $html = preg_replace($pattern, $replace, $html); But this only works if the original <a> tag has no special attributes, such as an id, style, target, title or another class. If it already has a class I want to replace it with my new class. 2. To find all hyperlinks in a text I am using the following preg_match_all: preg_match_all( '#<a\s (?= [^>]* href=" (?P<href> [^"]*) ")|) (??= [^>]* title=" (?P<title> [^"]*) ")|) (??= [^>]* class=" (?P<class> [^"]*) ")|) (??= [^>]* target=" (?P<target>[^"]*) ")|) [^>]*> (?P<text>[^<]*) </a> #xi', $html, $matches, PREG_SET_ORDER ); This works well, but it doesn't find links with single quotes. So it'll find <a href="something"> but not <a href='something'> Can someone help me with this? I have been struggling with this for a while. Thank you.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.