If you had a text area that contained [LINK=some url]some website[/LINK], how would you write a PHP script to convert that into a clickable link when the form data was output into the page?
@scragarAug 15.2008 — #[code=php]preg_replace("/[link=(.*?)](.*?)[/link]/i", "<a href='$1'>$2</a>", $str);[/code]untested, but it all works out logically.
@scragarAug 15.2008 — #( )</URL>bits of a regexp inside brackets get stored as $1 for the first, then $2 for the second and so on up to 99 .repesents any character *say's any number, I should really have used+to say 1 or more, edit that. ?normaly means optional, but when right after a * or + it turns greedy search off, meaning that it matches the smallest string it can, rather than matching the largest it can:[code=php]echo preg_replace("/a.*c/", "d", 'abc-abc');// greedy on, result is 'd' echo preg_replace("/a.*?c/", "d", 'abc-abc');// greedy off, result is 'd-d'[/code]
@Joseph_WitchardauthorAug 15.2008 — #bits of a regexp inside brackets get stored as $1 for the first, then $2 for the second and so on up to 99[/QUOTE]
Sorry, but I don't understand what you mean?
smallest string it can, rather than matching the largest it can[/QUOTE]
@scragarAug 15.2008 — #Sorry, but I don't understand what you mean? [/quote]I'm not very good at explaining this stuff, but for each set of brackets the preg_replace function uses a $n variable for it, so $1 is the first set of brackets, $2 is the second... $99 is the 99th set of brackets. It only allows 99 sets of brackets mapped in this way(which is not to say you can't have more than 99 sets of brackets, only that you can only use the $n variables for the first 99).
http://php.net/preg_replace -- read the manual(skip to replacement in the parameters section) if you still don't understand what I mean, although I personally don't think it explains it much better.
If you were outputting a rather large string (like a message board post), how could you use that function multiple times for features in addition to hyperlinks, such as bold text, larger text, etc.?