Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

strip tags error in logs


14steve14

Recommended Posts

I have just looked in my error logs and found the following error. I recently added a contribution to add the products description on certian pages.

 

PHP Warning: strip_tags() expects parameter 1 to be string, array given in includes/modules/product_listing.php on line 115

 

Part of line 115 is

 

. strip_tags($description['products_description']) .

 

I have changed it to

 

. strip_tags($description['products_description'], "") .

 

There now does not seem to be any error, and the site works as it should. Is this the correct way to sort this problem

REMEMBER BACKUP, BACKUP AND BACKUP

Link to comment
Share on other sites

Here is the explanation for strip_tags() function

 

It looks like with the change you did, you added some "allowed tags", but nothing in there. To be honest, I don't know what php understand it has to do in this case

 

Anyway, I think the warning was not about any missing parameters, but about the product description it self. Is it possible that this is empty at some point/for some products, that's why the warning?

 

Maybe you should validate that product description is not empty before applying the strip_tags

Link to comment
Share on other sites

strip_tags() wants a string for its first (mandatory) argument, and according to the error message it's seeing an array. Check that the 'product_description' element is actually set and not empty. Your "fix" just tells it there are no tags to keep (empty string), which is the default anyway. osC 2.3.1 product_listing.php does not by default call strip_tags(), so this must be an add-on gone awry (or doing insufficient checking and validation).

 

... . ((isset($description['products_description'] && !empty($description['products_description'])? strip_tags($description['products_description']): '') . ...

Link to comment
Share on other sites

Phil, thanks for your advice.

 

The code has been added to add a short description below the product name. It has been added to includes/new_products and several other places.

 

The code that had been added is

 

if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {
   $new_products_query = tep_db_query("select p.products_id, p.products_image, [color=#FF0000]trim(substring(pd.products_description, 1, 200)) as products_description, p.p[/color]roducts_tax_class_id, pd.products_name, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);
 } else {
   $new_products_query = tep_db_query("select distinct p.products_id, p.products_image, tr[color=#FF0000]im(substring(pd.products_description, 1, 200)) as products_description, p.[/color]products_tax_class_id, pd.products_name, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . (int)$new_products_category_id . "' and p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);
 }

 

Then i have added

 

$new_prods_content .= '<td width="33%" align="center" valign="top" class="newproductsbgtd"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $new_products['products_image'], $new_products['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'class="imageborder"') . '</a><br /><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '" class="product_name">' . $new_products['products_name'] . '[color=#FF0000]</a><br /> '. strip_tags($new_products['products_description'], "") . '... <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']). '" class="read_more">' . LINK_READ_MORE . '</a><br /><[/color]span class="productPrice">' . $currencies->display_price($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])) . '</span></td>';

 

Could you take a look and see if this is right please.

REMEMBER BACKUP, BACKUP AND BACKUP

Link to comment
Share on other sites

Before submitting $new_products['products_description'] to strip_tags(), where do you check that $new_products['products_description'] exists (isset) and is not empty? I don't see it.

 

If it works this way, with the empty string second argument to strip_tags(), I would say that's a bug in PHP that it handles a missing first argument that way. In other words, my preference would be to ensure that I only feed a valid string as strip_tag's first argument, as it is supposed to work with no second argument. The next release of PHP could very well fix this bug, leaving you to fix your code again.

Link to comment
Share on other sites

... in other words, what you could do is

 

$my_description = isset($new_products['products_description']) && !empty($new_products['products_description'])? strip_tags($new_products['products_description']): '' ;

 

Thats basically what @@MrPhil posted

 

Then you can use $my_description wherever you want to have it

Link to comment
Share on other sites

Phil, once again you are right. I have just found the addon that i used http://addons.oscommerce.com/info/7875. It has a support thread there so i may ask the question again there and see what gets said. In the mean time i have been looking for another similar addon and may have found a different method of coding this, which does also work. I am going to spend a while comparing the code edits.

 

I have also notice how headertags seo adds a description on the product listing pages so this may come in helpful also.

REMEMBER BACKUP, BACKUP AND BACKUP

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...