English 中文(简体)
摘录 网址的html网页的内容
原标题:Extract a content of a html page in php
  • 时间:2012-01-16 10:05:21
  •  标签:
  • php

可从中提取<代码><<<<>>>>/代码>的内容。 网页从<one> and end with </one> in php。 如果有的话,任何人都可以找到某些样本。

问题回答

You should have a look at the DOMDocument reference.

该实例是一份html文件,创建了,并贴上了标签:

libxml_use_internal_errors(true);
$dom = new DOMDocument;
$dom->loadHTMLFile( http://example.com );
libxml_use_internal_errors(false);

$body = $dom->getElementsByTagName( body )->item(0);

echo $body->textContent; // print all the text content in the body

你们还应检查以下资源:

DOM API Documentation
XPATH language specification

You can also try to use non-DOM solution based on strpos function:

$html = file_get_contents($url);
$html = substr($html,stripos($html, <body> )+6);
$html = substr($html,0,strripos($html, </body> ));

stripos is case insensitive version of strpos, strripos is case insensitive rightmost position version of strpos.

希望这将有助于你们!





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签