我的问题是我无法捕获此标记内的文本:
<p class="name">
" Eau de Toillete for Men, Spray 110ml " </p>
如您所见,文本用引号引起来
“香水的Eua男士用110毫升喷雾剂“
这是我的代码:
$pos1 = ".h2marca";
$pos2 = "[id=landing-submarca-perfume] h1";
$pos3 = "[class=name]";
$pos4 =".price";
$contador = 0
while (!empty($titulo3 = trim($html2->find($pos3,$contador)->plaintext)))
{
$titulo1 = trim($html2->find($pos1,0)->plaintext);
$titulo2 = trim($html2->find($pos2,0)->plaintext);
$titulo3 = trim($html2->find($pos3,$contador)->plaintext);
$titulo3 = str_replace("for Women, ","",$titulo3);
$titulo3 = str_replace("for Men, ","",$titulo3);
$titulo= $titulo1 . " " . $titulo2 . " " . str_replace("."," ",$titulo3);
$precio = trim($html2->find($pos4,$contador)->innertext);
$contador++;
}
我需要使用“ $ contador”,因为此网络中还有其他添加项,需要捕获全部。
$título3捕获一个空白空间。
我需要捕获文本而不删除$ contador变量
您能帮我吗?这是示例网站http://www.fundgrube.es/es/perfumes/aramis/aramis.html
谢谢!。
$split_this = '<p class="name">
" Eau de Toillete for Men, Spray 110ml " </p>';
$split_this = strip_tags($split_this, '');
$split_this = str_replace('"','',$split_this);
$split_this = trim($split_this);
$split_this = '"' . $split_this . '"';
给<p id="ptag1">
标签一个ID并放置一个隐藏的输入
<input type="hidden" name="ptag_value" />
可以使用JavaScript进行设置
document.getElementById('ptag_value').value = document.getElementById('ptag1').innerHTML;
如果他们的服务器支持fopen
$handle = fopen("http://www.fundgrube.es/es/perfumes/aramis/aramis.html", "r"); $contents = stream_get_contents($handle); $explode( '<p class="name">', $contents ); // may not work echo $contents[0]; // 1, 2, 3 , 4, etc
或
strip_tags($contents, '<p>'); // should preserve the p tags
否则使用空格''
strip_tags($contents, ''); // not entirely predictable but can work
应该只保留所有文本,不带任何html。其他示例:https://stackoverflow.com/questions/15281124/php-split-explode-stringstrong text
require_once('simple_html_dom.php');
$html = <<<EOF
<p class="name">
" Eau de Toillete for Men, Spray 110ml " </p>
EOF;
$dom = str_get_html($html);
echo $dom->find('p.name', 0)->plaintext;
#=> " Eau de Toillete for Men, Spray 110ml "