替换PHP变量的内容(存储的HTML标签)
我想从PHP变量( $ html_content
c
I want to replace <a>
tag contents from PHP Variable ($html_content
)...
变量 $ html_content
值如下所示:
$html_content= "<table>
<thead>
<tr><th>Customer</th><th>Age</th><th>A</th></tr>
</thead>
<tbody>
<tr><td>Test 1</td><td>25</td><td><a href='www.google.com'>Link</a></td></tr>
<tr><td>Test 2</td><td>30</td><td><a href='www.yahoo.com'>Link</a></td></tr>
<tr><td>Test 3</td><td>31</td><td><a href='www.rediff.com'>Link</a></td></tr>
...
...
...
</tbody>
</table>
我要替换字符串中的内容每个最终< td>
每个< tr>
的内容包含< a& ;
标签。
I want to replace content in string every last <td>
content of every <tr>
which contains <a>
tag.
样本行结果:
<tr><td>Test 1</td><td>25</td><td>Action will be taken soon.</td></tr>
<tr><td>Test 2</td><td>30</td><td>Action taken yesterday</td></tr>
...
...
我需要结果来替换每一行具有不同的内容值。内容取自表格。只有我想要替换的特定客户操作。
I need result to replace every row with different content values. The content is taken from table. The particular customer action only i want to replace.
CUSTOMER TABLE:
------------------------------------------------------
id customer age action
------------------------------------------------------
1 Test 1 25 Action will be taken soon
2 Test 2 30 Action taken yesterday
3 Test 3 31 Action will take tomw
4 Kumar 28 Suspended
...
...
...
------------------------------------------------------
使用此表格,我已将筛选结果显示在一个页面中,而无需执行描述,而不是< a>
标签。 (此结果是名为 reports.php
的页面的一部分)。
我想要导出这些记录只有使用操作
字段描述到PDF(我使用HTML到PDF类)。
在该页面中,我已将这些HTML值发送到该页面,并存储在 export_pdf.php中的PHP Variable(
$ html_content
)中/ code> page ...
using this table i have shown filtered result in one page without action description instead of <a>
tag. (This result is part of that page named reports.php
).
I want to export these records only with action
field description to PDF(I'm using HTML to PDF class).
In that page i had sent to these HTML values to that page and storing in PHP Variable($html_content
) in export_pdf.php
page...
表格记录是不是固定大小 ...它是基于生成排序的结果。
The table records is not fixed size... It's based on generating result from sorting.
请任何人帮助我...
提前感谢...
Please anyone help me... Thanks in advance...
请尝试以下代码:
$html_content= preg_replace("/<a[^>]+\>(.*?)<\/a>/i", "Action will be taken soon.", $html_content);
使用 foreach
在查询
foreach($row = mysql_fetch_assoc($result))
{
$html_content = preg_replace("/<a[^>]+\>(\w+)<\/a>/i", $row['action'], $html_content);
}
输出
Output
<table>
<thead>
<tr><th>Customer</th><th>Age</th><th>A</th></tr>
</thead>
<tbody>
<tr><td>Test 1</td><td>25</td><td>Action will be taken soon.</td></tr>
<tr><td>Test 2</td><td>30</td><td>Action will be taken soon.</td></tr>
<tr><td>Test 3</td><td>31</td><td>Action will be taken soon.</td></tr>
</tbody>
</table>