我一直在思考的奇怪问题。我有一个包含 HTML 的字符串,其中可能带有超链接。考虑下面的文字:
Hello this is my EXAMPLE string of html here's a <tag> and here's another </tag>. Blah blah I'm going to hyperlink some stuff with <a href="http://www.example.com/> anchor text </a> and then finish my sentence.
正如您在上面看到的,该短语anchor text
是指向 的超链接的锚文本example.com
。
我希望能够搜索类似anchor
or的子字符串,example
并确定每次出现是否是超链接的一部分,是否是锚文本、url 或a
标签。
优选地,对于搜索项的每次出现,将返回一个带有真/假的数组。不区分大小写的搜索会很好,如果它返回匹配的事件会很好,所以我们会知道大小写等。上述示例的理想响应是这样的:
$array[0][0] = "EXAMPLE"
$array[0][1] = false
$array[1][0] = "example"
$array[1][1] = true
每次出现的索引也可能是返回的有用信息。谢谢!