On 13/11/06, Chris <[EMAIL PROTECTED]> wrote:

<?php
function makeLink($matches) {
        $returnString="<b>" . $matches[1] . "</b>";
        return $returnString;
}

$articleText="This is a very [long] string.";
$articleText=preg_replace_callback('/\[([a-z]+)\]/i' , "makeLink",
$articleText);
print $articleText . "\n";
?>


The callback takes whatever the regular expressions returns (alpha
characters between [ and ]) and runs it through function "makeLink".

Not sure how that will go with multiple []'s etc in the same string but
it should get you started.


I didn't know that I had to call the function like that- I don't
remember ever seeing it called that way. Also, I must google the
meaning of the (~+) in the regex.

Thank you very much, Chris. I very much appreciate the assistance.
Know that I am learning, not just asking for hand-holding!

Dotan Cohen

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to