我需要帮助编写一个将HTML字符串转换为有效XML标记名称的正则表达式函数.例如:它需要一个字符串并执行以下操作:
Run Code Online (Sandbox Code Playgroud)Ex: Input: Date Created Ouput: Date_Created Input: Date<br/>Created Output: Date_Created Input: Date\nCreated Output: Date_Created Input: Date 1 2 3 Created Output: Date_Created
基本上,正则表达式函数应该将HTML字符串转换为有效的XML标记.
一些正则表达式和一些标准函数:
function mystrip($s)
{
// add spaces around angle brackets to separate tag-like parts
// e.g. "<br />" becomes " <br /> "
// then let strip_tags take care of removing html tags
$s = strip_tags(str_replace(array('<', '>'), array(' <', '> '), $s));
// any sequence of characters that are not alphabet or underscore
// gets replaced by a single underscore
return preg_replace('/[^a-z_]+/i', '_', $s);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1629 次 |
| 最近记录: |