本文介绍了在忽略 HTML 标签的同时查找子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要匹配部分字符串同时忽略 HTML 标签.这意味着如果用户想在源代码中查找字符串foo and foo1".

I need to match parts of string whilst ignoring HTML tags. Which means if user wants to look for string "foo and foo1" in source code.

Two strings, <u>foo</u> and foo1

由于标签的原因,他无法匹配.

He'd not get the match, because of the tags.

我尝试过正则表达式,但由于标签可以不必存在,所以它似乎太复杂了.

I've tried regex, but since the tags can and don't have to be there, it seems rather too complicated.

它不是服务器端脚本.这将是一个从控制台运行的应用程序.

It's not server-side script. It'd be an application run from console.

更具体地说:它用于语法高亮.所以用户希望foo 和 foo1"为斜体,但它的一部分已经下划线并且无论如何都不会匹配.这就是我不能剥离字符串的原因.

To be more specific: it is for syntax highlight. So user wants "foo and foo1" to be italic, but part of it is already underline and wouldn't match anyway. That's why I can't strip the string.

推荐答案

使用 PHP 函数 strip_tags 从文本中删除 HTML 标签.然后进行搜索.

Use the PHP function strip_tags to remove the HTML tags from the text. Then do your search.

http://php.net/manual/en/function.strip-标签.php

这篇关于在忽略 HTML 标签的同时查找子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 01:07