AUTOMATICALLY CREATING ACTIVE LINKS FROM URLS IN TEXT BOX FIELDS USING THE BUILT IN HTMLPURIFY LIBRARY - Dec 29th, 2018


If you include a URL that contains http in a forum post, that URL is automatically converted to a live link.

I wanted to implement this in the recipes in my CMSB Cookbook, but couldn't figure out how until Daniel Loewe from
Interactive Tools came up with an answer.
According to Daniel, there's a PHP library called HTML Purifier (http://htmlpurifier.org/) built in to the CMSB code
that does much of the heavy lifting.

Here are 2 basic implementations of this function. The text for these examples is pulled from a text box called
$table_of_contentsRecord['recipe'].

1) for CMSB pages using the built in library.


<?php $recipe = ($table_of_contentsRecord['recipe']); ?>
<?php
$config = array();
$config['AutoFormat.Linkify'] = true;

$recipe = htmlPurify($recipe, $config);
echo
$recipe;
?>


2) for code that can be used outside of CMSB:

<?php $recipe = ($table_of_contentsRecord['recipe']); ?>
<?php
$recipe = preg_replace("|(https?://[\w\-@:%\+.~#?&//=]+)|", '<a href="\\1">\\1</a>', $recipe);
echo
$recipe;
?>


For a more complex implementation of htmlPurify have a look at
http://www.thecmsbcookbook.com/recipedetail.php?324



The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service