01. august 2003 - 10:11Der er
3 kommentarer og 1 løsning
Highlight søge tekst
Hejsa Jeg mangler en "funktion" til at markere mit søge resultat. Jeg har prøvet at bruge den som jeg har fundet på nettet men jeg kan ikke få dem til at virke.
Der bliver investeret massivt i AI. Teknologien er mere tilgængelig end nogensinde, og ambitionerne er høje. Alligevel oplever mange virksomheder, at resultaterne udebliver.
Ja det var måske ikke den bedste forklaring. Det jeg vil have er en funktion lige som google, der markere de ord som man har søgt på. Jeg har en funktion i asp som gør det men det hjælper jo ikke. Jeg har fundet nogle på nette men jeg kan ikke få dem til at virke.
Her er et eks. på en af dem som jeg ikke kan få til at virke:
/* markup_words - A function to place tags around specified words in a string of HTML text. Returns the modified text.
$sText (string, required) - The HTML text to examine.
$aWords (array, required) - An associative array of words to place markup around. Each word is a key, with the tag to be placed before it as a value. Eg, array('word'->'<a href="word">')
$sCloseTag (string, required) - The tag to be placed after each of the words (eg, '</a>')
$boolGlobal (boolean, required) - If true, replace all instances of the words in $aWords. If false, replace only the first one.
The function ignores instances of the words within HTML comments, HTML tags, and, if $sCloseTag = '</a>', HTML links.
Dependencies - check_ignore(). */ function markup_words($sText, $aWords, $sCloseTag, $boolGlobal) { // by default, don't markup anything in comments, tags, or links if($sCloseTag == '</a>') { $aIgnoreTokens = array('', '<', '>', '<a ', '</a>'); } else { $aIgnoreTokens = array('', '<', '>'); } // keep a lowercase copy of $sText for searching $sLower = strtolower($sText);
// store the sections of $sText that are within the $aIgnoreTokens tags into an array // for checking later. $aIgnoreSections = array(); for($i=0; $i= 1) { $sCharBefore = $sLower[$iPos-1]; } else { $sCharBefore = ''; } if($iPos < strlen($sLower)) { $sCharAfter = $sLower[$iPos + strlen($sWord)]; } else { $sCharAfter = ''; } if(eregi('[a-z]', $sCharBefore . $sCharAfter)) { $iPos++; continue; } // markup the word, and replace it in the larger text $sMarkedWord = $sOpenTag . substr($sText, $iPos, strlen($sWord)) . $sCloseTag; $sText = substr($sText, 0, $iPos) . $sMarkedWord . substr($sText, $iPos + strlen($sWord)); $sLower = substr($sLower, 0, $iPos) . $sMarkedWord . substr($sLower, $iPos + strlen($sWord)); // update the positions of the ignored sections $iTagLength = strlen($sOpenTag) + strlen($sCloseTag); for($i=0; $i= $aIgnoreSections[$i][0]) && ($iPos <= $aIgnoreSections[$i][1])) { return false; } } return true; }
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.