Re: Parsing brackets in text

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 13/11/06, Chris <dmagick@xxxxxxxxx> 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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux