You are here:  » Useful Functions

Support Forum



Useful Functions

Submitted by gregor on Tue, 2012-03-27 16:59 in

Hello, Just wondering if you have ever written a list of the most useful functions available in your various scripts? Things like tapestery_normalise and such ... what they do and when they could be useful. For example, if I include the product name within a link title tag, I must strip out or alter the quotes to avoid issues. I've run into many little problems like this along the way, and in most cases there was already an available solution in your code. Do you have a list of the most useful functions and what they do?

Thanks,
Gregor

Submitted by support on Wed, 2012-03-28 07:46

Hi Gregor,

Incorporating values into title, alt tags etc. would generally just require an htmlentities() call - but specifically using the ENT_QUOTES tag to ensure that the HTML attribute isn't broken, for example

  <a href='....' alt='<?php print htmlentities($product["name"],ENT_QUOTES,$config_charset); ?>'><?php print $product["name"]; ?></a>

Otherwise, tapestry_normalise($product["name"]) would actually yield an HTML safe version of the name anyway but this might lose some information from the name (also bear in mind that in most instances of a $product array in scope the variable that was created at import time $product["normalised_name"] will also be available.

The other main tapestry* function that may be of use is the tapestry_substr() function which create a shortened version of a string without breaking the string mid-word. The function definition is

tapestry_substr($text,$length,$append="")

Where $text is the input string to truncate; $length the length in bytes to truncate at the first SPACE character _after_ that offset; and finally $append is a string to add to the end of the return value IF it has been truncated, for example "..." to indicate that the paragraph has been truncated. This function is used to display the shortened descriptions on search result pages.

Hope this helps!

Cheers,
David.
--
PriceTapestry.com