While running the codes on local host it is showing an error of--
( ! ) Fatal error: Call to a member function find() on a non-object in
C:\wamp\www\crawler_based_search_engine\ajax_requests.php on line 130
Call Stack
# Time Memory Function Location
1 0.0151 162928 {main}( ) ..\ajax_requests.php:0
the codes from line 130 and beyond is as follows
$html = file_get_html($file_name);
// Find all links
foreach($html->find('a') as $element) //--this is line no 130
{
$url = $element->href;
$index = strpos($url,'q=https://');
if($index > 0)
{
$index2 = strpos($url,'webcache');
if($index2 === false)
{
$index2 = strpos($url,'sa=U');
$url = substr($element->href,$index+2,$index2-$index-3);
echo "<a href='$url'>$url</a>";
echo '<hr/>';
}
}
}
because of this error my program is not fetching the links from the google
Related
I get these error from nowhere... What is wrong?
Warning: Division by zero in
/home//public_html/wp-content/plugins//includes/classes/controller/SearchPageController.php
on line 60
Warning: Invalid argument supplied for foreach() in
/home/vineanimals/public_html/wp-content/plugins/*/includes/classes/controller/ImportPageController.php
on line 70
Warning: array_merge(): Argument #1 is not an array in
/home//public_html/wp-content/plugins//includes/classes/controller/AImportPageController.php
on line 75
line codes:
line 60: $last = ceil($load_products_result['total'] / $load_products_result['per_page']);
line 70-75:
foreach ($product['sku_products']['variations'] as $var) {
if (isset($var['image'])) {
$product['all_images'][] = $var['image'];
}
}
$product['all_images'] = array_merge($product['all_images'], $this->woocommerce_model->get_images_from_description($product['description']));
}
A) Check your SQL query or Array feed
B) Then change
$last = ceil($load_products_result['total'] / $load_products_result['per_page']);
to:
$last = ( isset($load_products_result['per_page']) ? ceil($load_products_result['total'] / $load_products_result['per_page']) : 0)
C) and change the foreach as below:
if (is_array($product['sku_products']['variations'])){
foreach ($product['sku_products']['variations'] as $var) {
if (isset($var['image'])) {
$product['all_images'][] = $var['image'];
}
}
if (isset($product['description']) && is_array($product['all_images']) && is_array($this->woocommerce_model->get_images_from_description($product['description'])) )
$product['all_images'] = array_merge($product['all_images'], $this->woocommerce_model->get_images_from_description($product['description']));
}
I have a wordpress function that calls an API via Zebra_cURL and then uses json_decode to render the data appropriately. Yet there is erratic behavior and the following two errors are occurring: Trying to get property of non-object in [template file] on line 42 and through lines 50.
The lines in question are below:
//Course display callback function
function display_courses($result) {
$result->body = json_decode(html_entity_decode($result->body));
$title = $result->body[0]->{'Title'};
$term = $result->body[0]->{'Term'};
$meetings = $result->body[0]->{'Meetings'};
$status = $result->body[0]->{'Status'};
$course_number = $result->body[0]->{'OfferingName'};
$clean_course_number = preg_replace('/[^A-Za-z0-9\-]/', '', $course_number);
$credits = $result->body[0]->{'Credits'};
$instructor = $result->body[0]->{'InstructorsFullName'};
$description = $result->body[0]->{'SectionDetails'}[0]->{'Description'};
}
And then later I get an error Invalid argument supplied for foreach() in [template file] on line 64 which is:
//Call callback function
function parse_courses($result) {
$result->body = json_decode(html_entity_decode($result->body));
$course_data = array();
foreach($result->body as $course) {
[code]
}
[more code]
}
What exactly am I doing wrong here to cause these errors?
Here's a link to the full template file. Apologies for the vast code dump but I'm a bit in over my head with this.
You must always verify the output of functions/methods if the result if "as expected"
In your case, you did not check what json_decode() has returned
function parse_courses($result) {
$result = json_decode(html_entity_decode($result->body));
if ((!is_array ($result) && !is_object($result)) ||
(is_array($result) || count($result) == 0) ||
(json_last_error() != JSON_ERROR_NONE)) { // only for PHP >= 5.3.0
// log the error or warning here ...
// $input = $result;
// $output = print_r ($result, TRUE);
// Only for PHP >= 5.3.0
// json_last_error();
// json_last_error_msg();
return -1;
}
$result->body = $result;
$course_data = array();
foreach($result->body as $course) {
[code]
}
[more code]
}
I am building my first wordpress plugin and the error log is throwing up the following errors.
[06-Jul-2014 20:07:21 UTC] PHP Warning: array_merge(): Argument #2 is not an array in \wp-content\plugins\test-plugin\screen.php on line 49
[06-Jul-2014 20:07:21 UTC] PHP Warning: array_merge(): Argument #2 is not an array in \wp-content\plugins\test-plugin\screen.php on line 50
[06-Jul-2014 20:07:21 UTC] PHP Warning: end() expects parameter 1 to be array, null given in \wp-content\plugins\test-plugin\screen.php on line 323
[06-Jul-2014 20:07:21 UTC] PHP Warning: Invalid argument supplied for foreach() in \wp-content\plugins\test-plugin\screen.php on line 324
For the errors on line 49 & 50 the code is:
function register_settings() {
global $menu;
global $submenu;
$this->menus = array_merge(array(), $menu);
$this->submenus = array_merge(array(), $submenu);
$this->settings = get_option( $this->settings_name );
register_setting( 'admin-theme', $this->settings_name );
}
For the errors on lines 323 & 324 the code is:
function admin_menu() {
global $menu;
global $submenu;
// update menu
end( $menu );
foreach ($menu as $k=>&$v){
$id = explode(' <span', $v[0]);
$slug = 'menu_'.strtolower( str_replace( ' ','_',$id[0] ) );
$slug_hide = $slug.'_hide';
if($id[0] != NULL && $this->get_setting($slug) !== NULL){
$v[0] = $this->get_setting($slug). ( isset($id[1]) ? ' <span '.$id[1] : '' );
}
if( $this->get_setting($slug_hide) ){
unset($menu[$k]);
}
// update the submenu
if( isset($submenu[$v[2]]) ){
foreach ($submenu[$v[2]] as $key=>&$val){
$id = explode(' <span', $val[0]);
$slug_sub = $slug.'_'.strtolower( str_replace( ' ','_',$id[0] ) );
$slug_sub_hide = $slug_sub.'_hide';
if($id[0] != NULL && $this->get_setting($slug_sub) !== NULL){
$val[0] = $this->get_setting($slug_sub). ( isset($id[1]) ? ' <span '.$id[1] : '' );
}
if( $this->get_setting($slug_sub_hide) ){
unset( $submenu[$v[2]][$key] );
}
}
}
}
}
I can't seem to figure it out so if anyonecanhelp or point me in the right direction it would be greatly appreciated.
first you need to check your both variables is array
with is_array() like if(is_array($menu))
if not use type cast to convert variable in array
if(is_array($menu))
$this->menus = array_merge(array(), $menu);
else
$this->menus = array_merge(array(), (array)$menu);
if(is_array($submenu))
$this->submenus = array_merge(array(), $submenu);
else
$this->submenus = array_merge(array(), (array)$submenu);
I have a fatal error claiming that I have a string when I thought I had an array :
Fatal error: [] operator not supported for strings in /Applications/MAMP/htdocs/tankards_wordpress/wp-content/themes/tankardsleague/functions.php on line 566
and also the following warning :
Warning: in_array() expects parameter 2 to be array, string given in /Applications/MAMP/htdocs/tankards_wordpress/wp-content/themes/tankardsleague/functions.php on line 579
I am guessing that I have either a syntax problem somewhere? I thought I had initailized the variables but maybe I missed one? I would appreciate some more experienced eyes having a look.
function forum_subscribe_member_player()
{
global $user_ID;
$players= get_users();
foreach($players as $player)
{
$user_info = get_userdata($player->ID);
$playeremail = $user_info->user_email;
if(!empty($playeremail) && user_can( $player-> ID, 'contributor'))
{
$list = get_option('mf_forum_subscribers_1', array());
if( is_player_subscribed($player->ID)) //remove player if already exists (user clicked unsubscribe)
{
$key = array_search($playeremail, $list);
unset($list[$key]);
}
else
$list[] = $playeremail;
update_option('mf_forum_subscribers_1', $list);
}
}
}
function is_player_subscribed($user_ID)
{
if($user_ID)
{
$useremail = get_userdata($user_ID, 'user_email');
$list = get_option("mf_forum_subscribers_1", array());
if(!empty($list) && in_array($useremail, $list))
{
return true;
}
return false;
}
}
function call_forum_subscribe_member_player()
{
forum_subscribe_member_player();
}
line 566 is $list[] = $playeremail; line 579 is if(!empty($list) && in_array($useremail, $list))
well, you can type-cast the $list to an array to make sure it's always an array even if the initial value is null/empty/etc (basically any type except array):
$list = (array)get_option('mf_forum_subscribers_1', array());
I have looked but it seems I can't find the right answer or I don't have the skills for that. The thing is I'm getting this error:
Notice: Undefined variable: node in include() (line 69 of /home/xwebmedia/public_html/ltr/sites/all/themes/ltr/page.tpl.php).
and the code I'm using is:
<?php
if (count($node->field_adds) != 0)
{
foreach($node->field_adds['und'] as $key => $value)
{
$nid = $value['nid'];
$mywidget = node_view(node_load($nid));
print drupal_render($mywidget);
}
}
?>
Thing is everything is working fine, I get my widgets with adds in sidebar, but I am having this notice of error.
I know that I need to define a variable in template.php but I tried something it didn't work.
Any suggestions?
Check that $node has been set.
<?php
if (isset($node) && count($node->field_adds) != 0)
{
foreach($node->field_adds['und'] as $key => $value)
{
$nid = $value['nid'];
$mywidget = node_view(node_load($nid));
print drupal_render($mywidget);
}
}
?>
The page template file doesn't have a $node variable by default (you can have pages that aren't nodes so it's not required).
The menu_get_object() function is your friend here:
$node = menu_get_object();
if ($node) {
...
}