on 31/7/06 Ronald J Kimball wrote:
>BBEdit and PHP both use Perl-Compatible Regular Expressions, so I don't
>know why it's not working for you in PHP. Perhaps you could show a little
>more of the code you're using?
Thanks for your reply, this is the function that I'm using - it is used to parse
text and insert highlighted 'glossary terms' with definitions by means of a
simple <span> tag with a title.
What I want to avoid is placing a <span> tag inside an image title, for
instance, as this would break the HTML page completely.
The $mytext variable passed to the function contains simple html paragraphs with
the occasional image tag.
--------------------------------
function add_glossary($mytext) {
global $conn;
$sql = "SELECT glossary_term, glossary_definition FROM glossary_table";
$result = mysql_query($sql);
if($result && mysql_num_rows($result)) {
while($row = mysql_fetch_assoc($result)) {
$string = $row['glossary_term'];
$pattern = "'(?!<.*?)$string(?![^<>]*?>)'si";
if (preg_match($pattern, $mytext, $match)) {
$replacement_str = '<span class="glossary"
title="'.$row['glossary_definition'].'">'.$match[0].'</span>';
$mytext = str_replace($match[0],$replacement_str,$mytext) ;
}
}
}
return $mytext;
}
--------------------------------
Nicklas
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <[EMAIL PROTECTED]>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
To unsubscribe, send mail to: <[EMAIL PROTECTED]>