如何在div类后添加按钮链接

  • 本文关键字:添加 按钮 链接 div php
  • 更新时间 :
  • 英文 :


我有一个内容html

$output = '<div class="elementor-image-box-wrapper">
<div class="elementor-image-box-content">
<h3 class="elementor-image-box-title"><a href="#">Industrial</a></h3>
<p class="elementor-image-box-description">With OT’S tailored workwear solutions, you can op for a comprehensive program that takes care of your requirements entirely or...</p>
</div>
</div>';

我使用preg_replace在段落类element -image-box-description中添加按钮链接

$link = '<a href="#">Read more</a>';
$output = preg_replace( '/^<p class="elementor-image-box-description">(.*)</p>$/', '<p class="elementor-image-box-description">$1</p>'.$link, $output );

echo $输出;

但结果不工作

我假设你把所有的html放在$output中,你想改变一些部分。

我建议用另一种方法做这件事。

为组件创建PHP文件

my-component.php:

<div class="elementor-image-box-wrapper">
<div class="elementor-image-box-content">
<h3 class="elementor-image-box-title"><a href="#">Industrial</a></h3>
<p class="elementor-image-box-description">With OT’S tailored workwear solutions, you can op for a comprehensive program that takes care of your requirements entirely or...</p>
<?php echo $link; ?>
</div>
</div>

那么你可以

$link = '<a href="#">Read more</a>';
ob_start();
require_once('my-component.php');
$output = ob_get_clean();

最新更新