0

I have a question regarding the DomDocument

In my previous questoin.. How to detect certain characters and wrap them with another string?

I can get the assign table to the string. However, there are some table cell that contains

<input type='text' value='input value'/>

so it's like

<td><input type='text' value='input value'/></td>

I want to remove the input tag but still display the 'input value' in my cell as there is no input box. I need it because I need to display my string in my email.

I can't really do it in the client side.

Is there anyway to do this? Thanks.

4

1 回答 1

2

DomDocument您可以使用和 适当的提取输入值XPath

$html = "<td><input type='text' value='input value'/></td>";
$dom = new DOMDocument();
$dom->loadHTML($html);

$xpath = new DOMXPath($dom);

$inputtags = $xpath->query('//input[@type="text"]');
foreach ($inputtags as $tag) {
    $value = $tag->getAttribute('value');
}

输出:

input value

注意:此处使用的 XPath 仅用于演示目的。可能有多个输入类型为 as 的元素,text使用更可靠的 XPath 可能是个好主意。但是,这应该可以帮助您入门。

演示!

于 2013-08-27T19:11:39.840 回答