'-d' . $departmentId . '/';
if ($page > 1)
$link .= 'page-' . $page . '/';
return self::Build($link);
}
public static function ToCategory($departmentId, $categoryId, $page = 1)
{
CHAPTER 7 ?– SEARCH ENGINE OPTIMIZATION 200
$link = self::CleanUrlText(Catalog::GetDepartmentName($departmentId)) .
'-d' . $departmentId . '/' .
self::CleanUrlText(Catalog::GetCategoryName($categoryId)) .
'-c' . $categoryId . '/';
if ($page > 1)
$link .= 'page-' . $page . '/';
return self::Build($link);
}
public static function ToProduct($productId)
{
$link = self::CleanUrlText(Catalog::GetProductName($productId)) .
'-p' . $productId . '/';
return self::Build($link);
}
public static function ToIndex($page = 1)
{
$link = '';
if ($page > 1)
$link .= 'page-' . $page . '/';
return self::Build($link);
}
4. Continue working on the Link class by adding the following method, CleanUrlText(), which is called by
the methods you??™ve updated earlier to remove bad characters from the links:
// Prepares a string to be included in an URL
public static function CleanUrlText($string)
{
// Remove all characters that aren't a-z, 0-9, dash, underscore or space
$not_acceptable_characters_regex = '#[^-a-zA-Z0-9_ ]#';
$string = preg_replace($not_acceptable_characters_regex, '', $string);
// Remove all leading and trailing spaces
$string = trim($string);
// Change all dashes, underscores and spaces to dashes
$string = preg_replace('#[-_ ]+#', '-', $string);
// Return the modified string
return strtolower($string);
}
CHAPTER 7 ?– SEARCH ENGINE OPTIMIZATION 201
5.
Pages:
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312