说我有一个接口CrawlerInterface与实现PageCrawler和FeedCrawler; 如果我们碰巧在控制器中需要两个类,那么如何通过构造函数注入实现?
以前我们使用中心ServiceProvider来注册(即App::bind)这样的类,但在大多数情况下我们只有一个接口的实现,所以这个问题还没有发生在我们身上.
PS:我也想知道这个问题是否表明我们应该拆分控制器.
更新:
感谢您的评论和回复,解释说,界面只有一个公共方法:crawl($uri),并且页面/提要抓取工具都将其实现为given a resource identifier, return resource.
我的后续问题:
假设我们处于calculator加法,减法和乘法共享同一个接口的情况下Operation,它只有一个公共方法run,在某些时候我们仍然会遇到这个问题吧?我们如何处理这些情况ServiceProvider?
我决定使用SimplePie来解析RSS和Atom Feeds.
我想做的是让人们通过文本字段输入RSS和Atom Feeds URL.
如果他们放置无效的RSS和Atom Feeds怎么办?
我知道无法通过SimplePie解析无效的Feeds.
但是我想知道Feeds是否能够通过SimplePie解析.
通过该过程,我想删除那些无效的RSS提要URL列表.
检查文档类型,XML或HTML将是查找有效性的第一步.
我怎么能用PHP做到这一点?还是有其他方法可以做我想做的事情?
我有一个PHP字符串,其中包含我从RSS源检索的以下HTML.我使用简单的馅饼,无法找到任何其他方式来分割这两个数据集<description>.如果有人知道在简单的馅饼中选择一个很棒的孩子.
<div style="example"><div style="example"><img title="example" alt="example" src="example.jpg"/></div><div style="example">EXAMPLE TEXT</div></div>
to:
$image = '<img title="example" alt="example" src="example.jpg">';
$description = 'EXAMPLE TEXT';
Run Code Online (Sandbox Code Playgroud) 我是php和simplepie的新手.我希望能够使用simplepie将图像URL存储到变量中.对于我的例子,我将使用ebay rss feed(http://deals.ebay.com/feeds/rss).我想要获取网址的图片位于<image src=标记中.当我使用代码
foreach ($feed->get_items() as $item):
?>
<?php echo $item->get_description(); ?>
<?php endforeach; ?>
Run Code Online (Sandbox Code Playgroud)
显示图像和说明,但我无法将图像URL存储到变量中.如何使用simplepie将图像URL存储到变量?
谢谢
我对 Wordpress 中的 RSS 提要进行了一些更改,我正在使用fetch_feed()向另一个网站显示数据。假设有 2 个网站,分别称为 #Wordpress1 和 #Wordpress2。这是我添加到#wordpress1functions.php文件中的代码
add_action('rss2_item', 'dw_add_data_to_rss');
function dw_add_data_to_rss(){
global $post;
if( $post->post_type == 'product' ) {
$product = new WC_Product( $post->ID );
$output = '';
$thumbnail_ID = get_post_thumbnail_id( $post->ID );
$thumbnail = wp_get_attachment_image_src($thumbnail_ID, 'thumbnail');
$output = '<post-thumbnail>';
$output .= '<url>'. $thumbnail[0] .'</url>';
$output .= '<width>'. $thumbnail[1] .'</width>';
$output .= '<height>'. $thumbnail[2] .'</height>';
$output .= '</post-thumbnail>';
$output .= '<price>' . number_format( $product->get_price() ) . ' ' . get_woocommerce_currency_symbol() . '</price>';
echo …Run Code Online (Sandbox Code Playgroud) 我正在使用SimplePie和PHP 5.3(启用了gc)来解析我的RSS提要.在执行以下操作时,这很有效且没有问题:
$simplePie = new SimplePie();
$simplePie->set_feed_url($rssURL);
$simplePie->enable_cache(false);
$simplePie->set_max_checked_feeds(10);
$simplePie->set_item_limit(0);
$simplePie->init();
$simplePie->handle_content_type();
foreach ($simplePie->get_items() as $key => $item) {
$item->get_date("Y-m-d H:i:s");
$item->get_id();
$item->get_title();
$item->get_content();
$item->get_description();
$item->get_category();
}
Run Code Online (Sandbox Code Playgroud)
内存调试超过100次迭代(使用不同的 RSS源):

但是在使用时$item->get_permalink(),我的内存调试看起来像100次迭代(使用不同的 RSS源).
代码产生问题:
foreach ($simplePie->get_items() as $key => $item) {
$item->get_date("Y-m-d H:i:s");
$item->get_id();
$item->get_title();
$item->get_permalink(); //This creates a memory leak
$item->get_content();
$item->get_description();
$item->get_category();
}
Run Code Online (Sandbox Code Playgroud)

我试过的事情:
get_link而不是get_permalink__destroy所提到这里(即使它应该是固定的5.3)目前的调试过程:
我似乎已经将问题追溯到SimplePie_Item::get_permalink- > SimplePie_Item::get_link- > …
我正在使用SimplePie和PHP 5.2.17通过WordPress插件feedwordpress解析我的RSS提要.如果我确保将此补丁用于simplepie(在IRI.php文件中),这样可以正常工作并且没有问题.
但是,如果我将PHP更改为使用版本5.3.28 - 内存泄漏(或其他一些内存泄漏)启动并且我的站点崩溃.知道可能导致它/如何解决它的问题?
(换句话说,这个补丁应该在5.2中工作而不是在PHP 5.3中有效吗?)
谢谢.
我希望通过Feed获取新闻或网站帖子的完整内容.但是我们知道许多网站只提供部分新闻或通过他们的Feed发布.
当然我知道存在一个称为SimplePie开发用于通过feed获取网站内容的脚本.但是此脚本不会检索新闻的完整内容.
当然我发现了一个叫做" Full-Text Feeds做" 的脚本.但这不是免费的.我想要一个免费的剧本.
你知道类似的剧本或方式来满足我的需求吗?
Ehrm.我知道这看起来很简单(就像馅饼,哈哈),但我一直在努力
Warning: /cache/ is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.
Run Code Online (Sandbox Code Playgroud)
这是我的情况.我有easypie从我的域上的各个级别和文件夹中提取.因此,如果它在一个地方工作,那么我在其他地方得到这个警告.(例如它在子文件夹中.)
所以,我试图通过编辑simplepie.inc文件中的第501行来指定实际的完整路径位置
var $cache_location = $_SERVER['DOCUMENT_ROOT'] . "/cache/";
Run Code Online (Sandbox Code Playgroud)
但是,这是语法错误.....
那么,A)为什么?我知道我错过了一些愚蠢的东西.
和B)有更好/更有效的方法来做到这一点?
谢谢你提前!
我正在尝试使用以下来自http://codex.wordpress.org/Function_Reference/fetch_feed#Usage的代码从我的个人网站获取 2 个最新帖子
<h2><?php _e( 'Recent news from Some-Other Blog:', 'my-text-domain' ); ?></h2>
<?php // Get RSS Feed(s)
include_once( ABSPATH . WPINC . '/feed.php' );
// Get a SimplePie feed object from the specified feed source.
$rss = fetch_feed( 'THISISWHEREMYURLGOES/' );
$maxitems = 0;
if ( ! is_wp_error( $rss ) ) : // Checks that the object is created correctly
// Figure out how many total items there are, but limit it to 5.
$maxitems = $rss->get_item_quantity( 2 …Run Code Online (Sandbox Code Playgroud) 我正在使用这个simplepie,我已将文件上传到我的主机.除了一件事,一切似乎都很好.我从中获取Feed的博客中包含图片,当我使用simplepie查看Feed时,图片不显示.当我用simplepie查看博客时,有没有办法让图像显示出来?
好的,对不起,我是新来的.我只是直接从网站上使用代码来尝试查看博客.我会把代码放在底部.所以,就像我说的那样,我只是想让图像显示在我正在阅读的博客上.除此之外,一切都表现得很好.
---标题信息---
<?php
// Make sure SimplePie is included. You may need to change this to match the location of simplepie.inc.
require_once('simplepie.inc');
// We'll process this feed with all of the default options.
$feed = new SimplePie();
// Set the feed to process.
$feed->set_feed_url('http://wordpress.homickdesign.com/feed/');
// Run SimplePie.
$feed->init();
// This makes sure that the content is sent to the browser as text/html and the UTF-8 character set (since we didn't change it).
$feed->handle_content_type();
// Let's begin our XHTML webpage …Run Code Online (Sandbox Code Playgroud) 我正在努力让 set_item_limit 发挥作用。提要很好,但只是渲染每个帖子。这是我正在使用的代码:
// Make sure SimplePie is included. You may need to change this to match the location of autoloader.php
// For 1.0-1.2:
#require_once('../simplepie.inc');
// For 1.3+:
require_once('php/autoloader.php');
// process this feed with all of the default options.
$feed = new SimplePie();
// Set which feed to process. http://simplepie.org/blog/feed/
$feed->set_feed_url('https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=Tweet_Yourself');
// Run SimplePie.
$feed->set_item_limit(5);
$feed->init();
// This makes sure that the content is sent to the browser as text/html and the UTF-8 character set (since we didn't change it). …Run Code Online (Sandbox Code Playgroud) 我正在研究新闻应用程序,我需要解析当前的新闻RSS (Really Simple Syndication).
我找到了SimplePie库来RSS轻松解析feed.
首先,我直接在服务器上使用了这个库php code.
<?php
// Make sure SimplePie is included. You may need to change this to match the location of autoloader.php
// For 1.0-1.2:
#require_once('../simplepie.inc');
// For 1.3+:
require_once('./php/autoloader.php');
// We'll process this feed with all of the default options.
$feed = new SimplePie("https://news.google.com/news/feeds?pz=1&cf=all&ned=us&hl=en&topic=h&num=3&output=rss");
// Set which feed to process.
// Run SimplePie.
$feed->init();
// This makes sure that the content is sent to the browser as …Run Code Online (Sandbox Code Playgroud) simplepie ×13
php ×12
rss ×7
wordpress ×3
memory-leaks ×2
feed ×1
html ×1
laravel ×1
laravel-4 ×1
validation ×1