PHP 简单 HTML DOM - 获取稀有标签内的文本

PHP Simple HTML DOM - Get text inside rare tag

我的问题是我无法捕获此标签内的文本:

<p class="name">
    "                        Eau de Toillete for Men, Spray 110ml     "       </p>

如您所见,文字在引号中

” 淡香水 男士,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 捕获一个空 space。

我需要在不删除 $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。其他示例:

对我来说效果很好:

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     "