find and replace keywords by hyperlinks in an html fragment, via php dom

That’s somewhat tricky, but you could do it this way: $html = <<< HTML <div><p>The CEO of the Dexia bank <em>has</em> just decided to retire.</p></div> HTML; I’ve added an emphasis element just to illustrate that it works with inline elements too. Setup $dom = new DOMDocument; $dom->formatOutput = TRUE; $dom->loadXML($html); $xpath = new DOMXPath($dom); $nodes … Read more

Regular expression to remove special characters in JSTL tags

The JSTL fn:replace() does not use a regular expression based replacement. It’s just an exact charsequence-by-charsequence replacement, exactly like as String#replace() does. JSTL does not offer another EL function for that. You could just homegrow an EL function yourself which delegates to the regex based String#replaceAll(). E.g. package com.example; public final class Functions { private … Read more

I need to match or replace an asterisk * in a batch environmental variable using only native Windows commands. Is this possible?

The easy answer is no. The problem that you’re encountering stems from the fact that the asterisk * is a special character when used with the SET search and replace method. It matches multiple characters in a limited, but still useful, way. You can learn about that here. The hard answer is Yes! I will … Read more

Remove or match a Unicode Zero Width Space PHP

This: $newBody = str_replace(“&#8203;”, “”, $newBody); presumes the text is HTML entity encoded. This: $newBody = str_replace(“\xE2\x80\x8C”, “”, $newBody); should work if the offending characters are not encoded, but matches the wrong character (0xe2808c). To match the same character as #8203; you need 0xe2808b: $newBody = str_replace(“\xE2\x80\x8B”, “”, $newBody);