php - 在标签和 str_replace() 之间查找文本
问题描述
代码编辑
我想在任何 2 个 html 标签之间查找文本<tag>
并</tag>
替换它。到目前为止,我让它在>
文本之间工作<
<?
$text = $_POST['text1'];
$one=array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
$two=array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
$preg = str_replace($one,$two,$text);
//this will remove text within brackets.
$text = preg_replace("/\>[^)]+\</",$preg, $text);
?>
我如何使它适用于所有 html 标签?任何帮助表示赞赏!
解决方案
您应该在 str_replace 之前执行 preg_match,例如:
$string=$_POST['text1'];
preg_match('#<tr>(.*?)</tr>#', $source, $string);
...
...
$str=str_replace($one,$two,$string[1]);
推荐阅读
- r - 比较 svy_vglm 回归模型的结果('survey','svy_VGAM','mitools','mice' in R)
- svg - 将 svg sprite maker 添加到 prepros
- python - 如何创建图神经网络数据集?(pytorch 几何)
- python - 本地人的 Python 绑定环境
- sap-cloud-sdk - V4 生成器 - OData V2 非简单函数导入参数
- javascript - 谷歌关闭 - goog.require 找不到 goog.structs.PriorityQueue
- javascript - 如何替换字符串中由 {} 括起来的所有子字符串?
- ios - 如何将base64String中的EC转换为SecKey
- python - 如何查看禁止某人的用户的名称?
- java - 这个错误在运行我的代码时向我显示,“找不到或加载主类 XX:MaxPermSize=1024m”是什么意思?