On 13/11/06, Roman Neuhauser <neuhauser@xxxxxxxxxx> wrote:
# dotancohen@xxxxxxxxx / 2006-11-13 01:35:44 +0200: > 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. It's done this way in all the examples on http://cz.php.net/manual/en/function.preg-replace-callback.php What documentation did you read?
In the first example on that page, it looks to me like it should just return the text "next_year", and not call that function. Obviously, it is my misunderstanding of the way that the funciton works, and not in the function itself. I do learn php from TFM and this list, not from a course. Just like in any learning environment, I could misinterpret what is taught to me and need to ask a question, or not even know that I misinterpreted and not know that I need to ask a question. This is a case of the latter, clearly, because I have never needed to do anything other than a simple str_replace until now.
> Also, I must google the meaning of the (~+) in the regex. No need to google: http://cz.php.net/manual/en/reference.pcre.pattern.syntax.php Skip the Differences From Perl section.
That I have read at least three or four times. I still don't capture all of it, but I try. You are correct, I should have referenced that right away. It won't hurt for me to read it again, too. Thank you. Dotan Cohen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php