mike12255 Posted July 10, 2009 Share Posted July 10, 2009 So this line of code has everything in it i need to know. #\[b\](.*?)\[/b\]#is' First thing i don't know is why the # symbol is at the beginning what does it do? Second thing i dont know is the (.*?) i take it it means and or something of that sorts? and the last thing i dont understand is the #is what does that do? Thanks for any help given Quote Link to comment https://forums.phpfreaks.com/topic/165518-solved-dont-know-what-a-couple-things-mean/ Share on other sites More sharing options...
ignace Posted July 10, 2009 Share Posted July 10, 2009 Wrong section. Here's a cheat sheet: http://www.addedbytes.com/cheat-sheets/regular-expressions-cheat-sheet/ Quote Link to comment https://forums.phpfreaks.com/topic/165518-solved-dont-know-what-a-couple-things-mean/#findComment-872994 Share on other sites More sharing options...
.josh Posted July 10, 2009 Share Posted July 10, 2009 It is a regular expression (regex) pattern. The short story is that it does a case-insensitive, multi-line match and capture everything between [ b ] ... [/ b ] (no spaces) tags (like ubb tags). Quote Link to comment https://forums.phpfreaks.com/topic/165518-solved-dont-know-what-a-couple-things-mean/#findComment-872995 Share on other sites More sharing options...
mike12255 Posted July 10, 2009 Author Share Posted July 10, 2009 so does it give (.*?) the value of $1? im loooking off this example: $format_search = array('#\[b\](.*?)\[/b\]#is', // Bold ([b]text[/b] '#\[i\](.*?)\[/i\]#is', // Italics ([i]text[/i] '#\[u\](.*?)\[/u\]#is', // Underline ([u]text[/u]) '#\[s\](.*?)\[/s\]#is', // Strikethrough ([s]text[/s]) '#\[quote\](.*?)\[/quote\]#is', // Quote ([quote]text[/quote]) '#\[size=([1-9]|1[0-9]|20)\](.*?)\[/size\]#is', // Font size 1-20px [size=20]text[/size]) '#\[color=\#?([A-F0-9]{3}|[A-F0-9]{6})\](.*?)\[/color\]#is', // Font color ([color=#00F]text[/color]) '#\[url=(.*?)\](.*?)\[/url\]#i', // Hyperlink with descriptive text ([url=http://url]text[/url]) '#\[url\](.*?)\[/url\]#i', // Hyperlink ([url]http://url[/url]) '#\[img\](.*?)\[/img\]#i'); // Image ([img=http://url_to_image]) // The matching array of strings to replace matches with $format_replace = array('<strong>$1</strong>', '<em>$1</em>', '<span style="text-decoration: underline;">$1</span>', '<span style="text-decoration: line-through;">$1</span>', '<blockquote>$1</blockquote>', '<pre>$1</'.'pre>', '<span style="font-size: $1px;">$2</span>', '<span style="color: #$1;">$2</span>', '<a href="$1">$2</a>', '<a href="$1">$1</a>', '<img src="$1" alt="" />'); Quote Link to comment https://forums.phpfreaks.com/topic/165518-solved-dont-know-what-a-couple-things-mean/#findComment-873006 Share on other sites More sharing options...
.josh Posted July 10, 2009 Share Posted July 10, 2009 no, the opposite. (.*?) give $1 its value. (...) are captures. First set of (..) go to $1, 2nd goes to $2, etc... Quote Link to comment https://forums.phpfreaks.com/topic/165518-solved-dont-know-what-a-couple-things-mean/#findComment-873018 Share on other sites More sharing options...
mike12255 Posted July 10, 2009 Author Share Posted July 10, 2009 ok so if my code had (.*?) in it three times there would be the variables $1 $2 and $3 if so i think i understand now and thanks for all your help! Quote Link to comment https://forums.phpfreaks.com/topic/165518-solved-dont-know-what-a-couple-things-mean/#findComment-873028 Share on other sites More sharing options...
.josh Posted July 10, 2009 Share Posted July 10, 2009 Mostly right. .*? is just some arbitrary pattern. The important part is the parenthesis. Any pattern can be inside the parenthesis. You can even have captures nested inside of captures. The variables $1, $2, $3, etc... populate in order of parenthesis appearance, from left to right. Quote Link to comment https://forums.phpfreaks.com/topic/165518-solved-dont-know-what-a-couple-things-mean/#findComment-873060 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.