Skip to content

Instantly share code, notes, and snippets.

@chattago2002
chattago2002 / truncateHtml.php
Created February 21, 2024 17:25
truncateHtml can truncate a string up to a number of characters while preserving whole words and HTML tags
<?php
/**
* truncateHtml can truncate a string up to a number of characters while preserving whole words and HTML tags
*
* @param string $text String to truncate.
* @param integer $length Length of returned string, including ellipsis.
* @param string $ending Ending to be appended to the trimmed string.
* @param boolean $exact If false, $text will not be cut mid-word
* @param boolean $considerHtml If true, HTML tags would be handled correctly
*
@chattago2002
chattago2002 / update-items-url.js
Created November 23, 2023 16:10
Remove current url from a list (as a menu)
jQuery(document).ready(function() {
updateItems(jQuery("#menu ul"));
})
// listEl is the menu/list element to be read.
// It could be a simple string or an array
function updateItems(listEl = null) {
if (!listEl) {
const currentUrl = jQuery(location).attr('href');
var listElArr = [];