Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何添加目标="_“空白”;关于现有的<;a href="&引用&燃气轮机</a>;?_Php_Html_Tags - Fatal编程技术网

Php 如何添加目标="_“空白”;关于现有的<;a href="&引用&燃气轮机</a>;?

Php 如何添加目标="_“空白”;关于现有的<;a href="&引用&燃气轮机</a>;?,php,html,tags,Php,Html,Tags,我有一个变量,在PhP中包含以下文本: $description = "Flash <a href=\"http://www.aaa.com/\">this coupon</a> <br > <a href="http://www.ggg.com/">Visit here</a> for details <br >"; 我正在寻找一个解决方案,即变量$description是由用户意外记录的。但是我需要系统通过将targe

我有一个变量,在PhP中包含以下文本:

$description = "Flash <a href=\"http://www.aaa.com/\">this coupon</a> <br > <a href="http://www.ggg.com/">Visit here</a> for details <br >";

我正在寻找一个解决方案,即变量$description是由用户意外记录的。但是我需要系统通过将target=“blank”添加到现有变量中并更新记录来发现并更正它。

如果您注意到标记的属性没有特定的顺序,您可以简单地替换您已经执行的
,但是您的代码将产生错误,因为您没有逃脱
在第二个链接中

$description = "Flash <a href=\"http://www.aaa.com/\" target=\"_blank\">this coupon</a> <br > <a href=\"http://www.ggg.com/\" target=\"_blank\">Visit here</a> for details <br >";

$description=str_replace(“我不知道您的确切含义。但是,建议在您的HTML中使用“并且仅”作为回音。
因此,它将是:

$description = "Flash <a href='http://www.aaa.com/' target='_blank'>this coupon</a><br ><a href='http://www.ggg.com/' target='_blank'>Visit here</a> for details <br >";
$description=“Flash
了解详细信息
”;
要添加目标,可以使用以下方法:

$string = preg_replace("/<a(.*?)>/", "<a$1 target=\"_blank\">", $string);

$string=preg\u replace(“/

你的问题是什么?为什么你不能完全按照这里概述的那样做?你可以完全按照你说的那样做,但你应该回避你的引用(即使在第一个例子中)或者可以考虑用单个引号包装它,并使用HTML属性的双引号。单配额内的单配额应该以“双配额”的方式逃脱,同样地,对于双配额,可以使用单一配额在双配额内而不需要任何逃逸,而副Velsi认为问题是如何,不知道代码< >代码>的URL可以注入。
target=“\u blank”
我正在寻找用户意外记录变量$description的解决方案。但我需要系统通过添加target=“blank”来发现并更正它进入现有变量并更新record.hi@hexblot,感谢您的评论。实际上,我正在寻找解决方案,变量$description是由用户意外记录的。但我需要系统通过添加target=“blank”来查找并更正它抱歉,可能是我误导了我的问题。我刚刚又更新了问题。你应该反过来做。
用于字符串,
用于html属性。虽然允许使用单引号,但双引号更为“标准”“html的方式。@eL Prova感谢它的工作……非常感谢appreciated@user1109161请标记为答案:)谢谢它能工作…非常感谢如果先使用其他标签,如
$description = str_replace('<a href="','<a target="_blank" href="',$description);
$description = "Flash <a href='http://www.aaa.com/' target='_blank'>this coupon</a><br ><a href='http://www.ggg.com/' target='_blank'>Visit here</a> for details <br >";
$string = preg_replace("/<a(.*?)>/", "<a$1 target=\"_blank\">", $string);