Dynamically Exclude Content In PHP Simple HTML DOM Parser

I am making a PHP-based application which will fetch content from a site using the PHP Simple HTML DOM Parser. I want to exclude some text between two HTML tags from the content dynamically. If the source code of the content is: Some description or content ETC ABC <span class="s"> May 3 2009 <b> ABC Some Text </b> Some photo or video... I want to remove all the text wrapp

动态排除PHP简单HTML DOM解析器中的内容

我正在制作一个基于PHP的应用程序,它将使用PHP Simple HTML DOM Parser从站点获取内容。 我想动态地从内容中排除两个HTML标签之间的一些文本。 如果内容的源代码是: Some description or content ETC ABC <span class="s"> May 3 2009 <b> ABC Some Text </b> Some photo or video... 我想将<span class="s">包装的所有文本移除到第一个<b> HTML标签,所以输出结果为: Some d

Playing Simple PHP Dom Parser In Advance

I want to do something advanced with PHP Simple HTML DOM Parser but can't understand how to do so.. What I want to do: Suppose we are getting some url from here foreach($result->find('a') as $element) $element->href and now i want to get its content as plain text but note that I am going to fetch full content from that pages. Suppose this script has a variable called $sn = 'li

提前玩简单的PHP Dom解析器

我想用PHP Simple DOM DOM解析器进行一些高级操作,但无法理解如何操作。 我想要做的是:假设我们从这里得到一些网址 foreach($result->find('a') as $element) $element->href 现在我想以纯文本形式获取其内容,但请注意,我将从该页面获取完整内容。 假设这个脚本有一个名为$sn = 'linkin park song';的变量$sn = 'linkin park song'; - 是否有任何方法从这些关键字从$sn页面中获取行 如果你不

wrong characters encoding DOMDocument php

i have some html content that all of its texts are Persian ! i want to give this content to DOMDocument by method DOMDocument::loadHTML($html) to do some stuff and then give it back by DOMDocument::saveHTML() ... but there is a problem in showing characters :-( for example "سلام" changed to "سلام", even I changed my script file encoding to UTF-8 but it doesn't work.

编码DOMDocument php的错误字符

我有一些html内容,它的所有文本都是波斯文! 我想通过方法DOMDocument :: loadHTML($ html)将这些内容提供给DOMDocument来做一些事情,然后通过DOMDocument :: saveHTML()将其返回......但是在显示字符时存在一个问题:-(例如“سلام”更改为“سٔاÙ...“,即使我将脚本文件编码更改为UTF-8,但它不起作用。 <?php $html = "<html><meta charset='utf-8' /> سلام</html>"; $doc = new DOMDocument('1.0'

How to make HTML5 work with DOMDocument?

I'm attempting to parse HTML code with DOMDocument, do stuff like changes to it, then assemble it back to a string which I send to the output. But there a few issues regarding parsing, meaning that what I send to DOMDocument does not always come back in the same form :) Here's a list: using ->loadHTML: formats my document regardless of the preserveWhitespace and formatOutput se

如何使HTML5与DOMDocument一起工作?

我试图用DOMDocument解析HTML代码,做类似于它的修改,然后将其组装回我发送给输出的字符串。 但是有几个关于解析的问题,这意味着我发送给DOMDocument的东西并不总是以相同的形式回来:) 这里是一个列表: 使用 - > loadHTML: 格式化我的文档,而不管preserveWhitespace和formatOutput设置(丢失预格式化文本上的空格) 当我有像<header> , <footer>等html5标签时,会给我带来错误,但是它们可以被抑

PHP DOMDocument, Unicode problems

I have some problem here $source = "<html><body><h1>&#8220;</h1></body></html>"; $dom = new DOMDocument(); $dom->loadHTML($source); echo $dom->saveHTML(); Output: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><body><h1>&ldquo;</h1&

PHP DOMDocument,Unicode问题

我在这里有一些问题 $source = "<html><body><h1>&#8220;</h1></body></html>"; $dom = new DOMDocument(); $dom->loadHTML($source); echo $dom->saveHTML(); 输出: <!DOCTYPE html PUBLIC“ - // W3C // DTD HTML 4.0 Transitional // EN”“http://www.w3.org/TR/REC-html40/loose.dtd”> <html> <body> <h1 >&ldquo; </ H1> </ BODY>

Parsing HTML Source to extract Anchor and Link tags href value

I am looking for some HTML Parser in PHP which can help me extract href values from the html source. I looked at phpQuery and its best but it is to be too overkill for my needs and cosume a lot of CPU doing the extra stuff that I dont need. I also checked $dom = new DomDocument(); $dom->loadHTML($html); but it has problems parsing HTML5 tags. Is there any better library/class or a

解析HTML源码以提取锚点和链接标记href值

我正在寻找一些PHP的HTML解析器,它可以帮助我从HTML源文件中提取href values 。 我查看了phpQuery及其最佳版本,但这对我的需求来说过于矫枉过正,并且耗费了大量CPU来完成我不需要的额外工作。 我也检查过 $ dom = new DomDocument(); $ dom-> loadHTML($ HTML); 但它在解析HTML5标签时遇到问题。 有没有更好的library/class或一种方法来做到这一点? 那么,你可以使用正则表达式来提取数据: $html = "Thi

Change encoding of an xml file in php

I have opened a server which is waiting for queries. When i send a query, the server will answer it and safe the results in an xml file. Problem is, that I can't use this xml properly because in the first line of the xml is now written: xml version="1.0 encoding="utf-8" if I change this in the editor into: xml version="1.0 encoding="iso-8859-1 than it works

在PHP中更改xml文件的编码

我打开了一个正在等待查询的服务器。 当我发送一个查询时,服务器将回答它并在xml文件中保存结果。 问题是,我无法正确使用这个xml,因为现在在xml的第一行写了: xml version =“1.0 encoding =”utf-8“ 如果我在编辑器中将其更改为: xml version =“1.0 encoding =”iso-8859-1 比它工作正常。 但是,而不是使用编辑器和我的手,我想要PHP来做到这一点? 谢谢 只是为了解决这个问题:我在xml文件中使用了str_replac

get the latest node value in xml file using php code

I am new wih xml file .. I want to get the latest node id value of xml file using php script and calculate it when I add one more node to this xml file .. something like this .. <id>2</id> and the next node will be <id>3</id> after adding... suppose that i have an xml file like below: <?xml version="1.0" encoding="UTF-8"?> <books> <book> <id>1

使用php代码获取xml文件中的最新节点值

我是新的wih xml文件..我想使用php脚本获取xml文件的最新节点id value ,并在我向此xml文件中添加一个更多节点时计算它..类似这样的内容.. <id>2</id>并且在添加...之后下一个节点将是<id>3</id> 假设我有如下的xml文件: <?xml version="1.0" encoding="UTF-8"?> <books> <book> <id>1</id> <name>Java</name> </book> <book> <i

Saving returned XML data in PHP to an XML file

I have a php file which requests xml data and displays it it the browser. The XML is displayed by: $xmlString = constructPostCallAndGetResponse($endpoint, $item, $postCode, $dist); $resp = simplexml_load_string($xmlString); echo htmlentities($xmlString); How do I save the returned XML to an XML file on my server? Ive read alot about DOM but keep going in circles. Can anyone suggest a simpl

将PHP中返回的XML数据保存为XML文件

我有一个PHP文件,它请求XML数据并将其显示在浏览器中。 XML通过以下方式显示: $xmlString = constructPostCallAndGetResponse($endpoint, $item, $postCode, $dist); $resp = simplexml_load_string($xmlString); echo htmlentities($xmlString); 如何将返回的XML保存到我的服务器上的XML文件中? 我已经阅读了很多关于DOM的内容,但是继续往下看。 任何人都可以提出一个简单的方法做到这一点? 保存到文件,与你的sinp

plus one to xml node value

This question already has an answer here: A simple program to CRUD node and node values of xml file [closed] 2 answers Try something like this: $objectX = "2"; // You get this value with $_POST or $_GET ... $xmlFileName = 'my.xml'; // You're XML file $xmlFile = file_get_contents($xmlFileName); // Saving the XML contents in a variable $objects = new SimpleXMLElement($xmlFile); $objectX = "o

加一个到xml节点的值

这个问题在这里已经有了答案: 一个简单的程序来CRUD节点和XML文件的节点值[关闭] 2个答案 尝试这样的事情: $objectX = "2"; // You get this value with $_POST or $_GET ... $xmlFileName = 'my.xml'; // You're XML file $xmlFile = file_get_contents($xmlFileName); // Saving the XML contents in a variable $objects = new SimpleXMLElement($xmlFile); $objectX = "object".$objectX; // The object name $objec